Results 1 to 16 of 16
  1. #1
    alvations is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default trying to set() values of in list of arraylist

    i've created a list that holds a list of arraylist. i'm trying to change the elements in my list using the ArrayList.set() function but i can't get the syntax right
    __________________________________________________ ___-

    List<List> sentences = new ArrayList<List>();

    List<List> each_sentence = new ArrayList<List>();

    ArrayList<String> iob = new ArrayList<String> ();
    ArrayList<String> pos = new ArrayList<String> ();
    ArrayList<String> word = new ArrayList<String> ();

    iob.add("pig");
    iob.add("cow");
    iob.add("horse");

    pos.add("eat");
    pos.add("ate");
    pos.add("eats");

    word.add("meat");
    word.add("grass");
    word.add("wheat");

    each_sentence.add(iob);
    each_sentence.add(pos);
    each_sentence.add(word);

    sentences.add(each_sentence);

    String change = "Pigs"

    ((List) ( ((List) (sentences.get(r).get(0))).get(s) ) ).set(s, change);

    // i want to change the element "pig" to "Pigs" but the set() takes in an object, i can't put in a string.
    //any idea on how to use the set() function in this situation??

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    First I'd recommend breaking this long ugly statement into simple parts:
    ((List) ( ((List) (sentences.get(r).get(0))).get(s) ) ).set(s, change);

    If you are getting error messages, copy them here.

    What class is the set() method in? What does the API doc say about how to use that method?

  3. #3
    alvations is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default

    ((List) ( ((List) (sentences.get(0).get(0))).get(0) ) ).set(0, change);

    Arraylist.set(index, Obj) as shown in the API

    it takes an object but my object is a string. is that a way to just cast the string into the obj?

    ((List) ( ((List) (sentences.get(0).get(0))).get(0) ) ) => x
    // simply means access the Arraylist that contains the String "pig"

    x.set(0,change).

    if we don't ignore the set(), is there any other way to replace the element "pig"??


    _____________________________
    Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
    at gather_datasssss.main(gather_datasssss.java:1148)
    ______________________________

    this is the error after i try to run it. compiling is no problem.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    First I'd recommend breaking the long ugly statement into simple parts.
    That will help you see where your cast problem is.

  5. #5
    alvations is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default

    if you system.out.print the following you get:

    sentences =>[ [[pig],[cow],[horse]], [[eat],[ate],[eats]], [[meat],[grass],[wheat]] ] , [ (second sentence if there is)]

    sentences.get(0) => [[pig],[cow],[horse]], [[eat],[ate],[eats]], [[meat],[grass],[wheat]]

    sentence.get(0).get(0) => [ [pig],[cow],[horse] ]

    (List) (sentences.get(0).get(0) ) => casting [ [pig],[cow],[horse] ] to access a single element

    ( (List) (sentences.get(0).get(0) ) .get(0) => [pig]

    (List) ( ((List) (sentences.get(0).get(0)) .get(0) ) => casting [pig] to a list, to use set()

    ( (List) ( ((List) (sentences.get(0).get(0)) .get(0)) ) .set(0, "Pigs")
    => trying to use the set() functions.

  6. #6
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Yes, that is the internal representation. You can do a cast to get a String.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  7. #7
    alvations is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default

    what do i cast? and how does the syntax look like? below are what i've tried to do but they all don't work.

    i'm simply trying to change the element "pig" to "Pigs".

    _________________________________________

    ((List)(((List) (sentences.get(0).get(0))).get(0)).set(0,"Pigs");

    i get this error when run,

    Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
    at gather_datasssss.main(gather_datasssss.java:1148)
    ______________________________________

    ((String)((List)(((List) (sentences.get(0).get(0))).get(0))).set(0,"Pigs");

    i get this error when compile


    gather_datasssss.java:1148: inconvertible types
    found : java.util.List
    required: java.lang.String
    ((String) ((List) (((List) (sentences.get(0).get(0))).get(0) ))).set(0 "Pigs");
    ^
    ______________________________________________

    ((List)(((List) (sentences.get(0).get(0))).get(0)).set(0, (String) "Pigs");

    i get this error when run

    Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
    at gather_datasssss.main(gather_datasssss.java:1148)

    __________________________________________________ ________

  8. #8
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    As you can see, your approach is really ugly.

    A much cleaner approach is to define a class Sentence that has three variables, and then just have a list of Sentence objects.

  9. #9
    alvations is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default

    ?? how would that look like? care to post an example?? thanks

  10. #10
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Like this:

    Java Code:
    import java.lang.String;
    import java.util.ArrayList;
    
    /*
    #  * Animals.java  
    #  *   
    #  * Copyright (C) 2008 Patrick Farrell  
    #  *   
    #  * This program is distributed in the hope that it will be useful,  
    #  * but WITHOUT ANY WARRANTY; without even the implied warranty of  
    #  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
     */
    
    /**
     * The <code>Animals</code> class implements
     * @author pfarrell
     */
    public class Animals {
        
        ArrayList<Sentence> theList = new ArrayList<Sentence>();
    
        public void firstStuff() {
             theList.add(new Sentence("pig", "eat", "anything"));
             theList.add(new Sentence("cow", "ate", "grass"));
             theList.add(new Sentence("hippy", "eats", "grass or brownies"));
        }
        public void dumpList() {
             for ( Sentence s : theList) {
                 System.out.println(s.getAnimal());
             }
        }
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
             Animals anInstance = new  Animals();
             anInstance.firstStuff();
             anInstance.dumpList();    
            
        }
    
    }
    And

    Java Code:
    public class Sentence {
        private String type;
        private String verb;
        private String food;
        public Sentence(String w, String v, String f) {
            type = w;
            verb = v;
            food = f;
        }
    public String getAnimal() { return type;}
    public String getVerb() { return verb;}
    public String getFood() { return food;}
    }
    I'll let you add the proper setters to the Sentence class

  11. #11
    alvations is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default

    thanks fishtoprecords. but i'll consider whether i want to change my few thousand lines of code. but if i were given this program:

    ArrayList<String> test = new ArrayList<String> ();
    List<List> test2 = new ArrayList<List>();
    List<List> test3 = new ArrayList<List>();
    test.add("pig");
    test2.add(test);
    test3.add(test2);

    how would i change the "pig" into "cow"? given that i cannot change my construction of the lists?

  12. #12
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    You really should not have thousands of lines of code, based on what you have described. My version does nearly all that you want in about 20.

    You have to add setAnimal(), setVerb() and setFood() to the sentence class.

    Then you just get a Sentence object from the list, call setAnimal() or
    setFood() or whatever.

    You seem to be missing some fundental Object Oriented concepts. Java is OO because you don't want thousands of lines of code.

  13. #13
    alvations is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default

    hahaha. you're right i don't have the OO mindset. classic case of C/C+ programmer.. hahaha. but i would have use structs and dynamic arrays.

    i've still 2 more modules to integrate into the program though

    let me give a clue about what i've programmed.
    ___________________________

    import java.io.*;
    import java.util.*;
    import java.lang.*;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Hashtable;
    import java.util.Vector;
    import java.util.Collections;


    public class gather_datasssss
    {

    public static void main(String args[]) throws Exception
    {
    int iobcount=0;int storecount=0; int sentencecount = 0;
    List<List> sentences = new ArrayList<List>();
    String punk = "[^0-9a-zA-Z].*";

    String filename[] = new String[100];
    for(int i=0;i<100;i++) filename[i] = "";
    /* for(int i=0;i<100;i++)
    {
    filename[i] = "";
    String jstring = Integer.toString(i+100);
    filename[i] = filename[i].concat(jstring);
    filename[i] = filename[i].concat(".txt");
    }*/

    for(int i=0;i<100;i++)
    {
    if(i<10)
    {
    int j=i+1;
    String jstring = Integer.toString(j);
    filename[i] = filename[i].concat("00");
    filename[i] = filename[i].concat(jstring);
    filename[i] = filename[i].concat(".txt");
    // System.out.println(filename[i]);
    }
    else
    {
    int j=i+1;
    String jstring = Integer.toString(j);
    filename[i] = filename[i].concat("0");
    filename[i] = filename[i].concat(jstring);
    filename[i] = filename[i].concat(".txt");
    // System.out.println(filename[i]);
    }
    }


    for(int i=0; i<100; i++)
    {

    List<List> each_sentence = new ArrayList<List>();
    List<List> each_sentence2 = new ArrayList<List>();
    List<List> each_sentence3 = new ArrayList<List>();
    List<List> each_sentence4 = new ArrayList<List>();
    List<List> each_sentence5 = new ArrayList<List>();
    List<List> each_sentence6 = new ArrayList<List>();
    List<List> each_sentence7 = new ArrayList<List>();
    List<List> each_sentence8 = new ArrayList<List>();
    List<List> each_sentence9 = new ArrayList<List>();
    List<List> each_sentence10 = new ArrayList<List>();
    List<List> each_sentence11 = new ArrayList<List>();
    List<List> each_sentence12 = new ArrayList<List>();
    List<List> each_sentence13 = new ArrayList<List>();
    List<List> each_sentence14 = new ArrayList<List>();
    List<List> each_sentence15 = new ArrayList<List>();
    List<List> each_sentence16 = new ArrayList<List>();
    List<List> each_sentence17 = new ArrayList<List>();
    List<List> each_sentence18 = new ArrayList<List>();
    List<List> each_sentence19 = new ArrayList<List>();
    List<List> each_sentence20 = new ArrayList<List>();

    ArrayList<String> iob = new ArrayList<String> ();
    ArrayList<String> pos = new ArrayList<String> ();
    ArrayList<String> word = new ArrayList<String> ();
    ArrayList<String> iob2 = new ArrayList<String> ();
    ArrayList<String> pos2 = new ArrayList<String> ();
    ArrayList<String> word2 = new ArrayList<String> ();
    ArrayList<String> iob3 = new ArrayList<String> ();
    ArrayList<String> pos3 = new ArrayList<String> ();
    ArrayList<String> word3 = new ArrayList<String> ();
    ArrayList<String> iob4 = new ArrayList<String> ();
    ArrayList<String> pos4 = new ArrayList<String> ();
    ArrayList<String> word4 = new ArrayList<String> ();
    ArrayList<String> iob5 = new ArrayList<String> ();
    ArrayList<String> pos5 = new ArrayList<String> ();
    ArrayList<String> word5 = new ArrayList<String> ();
    ArrayList<String> iob6 = new ArrayList<String> ();
    ArrayList<String> pos6 = new ArrayList<String> ();
    ArrayList<String> word6 = new ArrayList<String> ();
    ArrayList<String> iob7 = new ArrayList<String> ();
    ArrayList<String> pos7 = new ArrayList<String> ();
    ArrayList<String> word7 = new ArrayList<String> ();
    ArrayList<String> iob8 = new ArrayList<String> ();
    ArrayList<String> pos8 = new ArrayList<String> ();
    ArrayList<String> word8 = new ArrayList<String> ();
    ArrayList<String> iob9 = new ArrayList<String> ();
    ArrayList<String> pos9 = new ArrayList<String> ();
    ArrayList<String> word9 = new ArrayList<String> ();
    ArrayList<String> iob10 = new ArrayList<String> ();
    ArrayList<String> pos10 = new ArrayList<String> ();
    ArrayList<String> word10 = new ArrayList<String> ();
    ArrayList<String> iob11 = new ArrayList<String> ();
    ArrayList<String> pos11 = new ArrayList<String> ();
    ArrayList<String> word11 = new ArrayList<String> ();
    ArrayList<String> iob12 = new ArrayList<String> ();
    ArrayList<String> pos12 = new ArrayList<String> ();
    ArrayList<String> word12 = new ArrayList<String> ();
    ArrayList<String> iob13 = new ArrayList<String> ();
    ArrayList<String> pos13 = new ArrayList<String> ();
    ArrayList<String> word13 = new ArrayList<String> ();
    ArrayList<String> iob14 = new ArrayList<String> ();
    ArrayList<String> pos14 = new ArrayList<String> ();
    ArrayList<String> word14 = new ArrayList<String> ();
    ArrayList<String> iob15 = new ArrayList<String> ();
    ArrayList<String> pos15 = new ArrayList<String> ();
    ArrayList<String> word15 = new ArrayList<String> ();
    ArrayList<String> iob16 = new ArrayList<String> ();
    ArrayList<String> pos16 = new ArrayList<String> ();
    ArrayList<String> word16 = new ArrayList<String> ();
    ArrayList<String> iob17 = new ArrayList<String> ();
    ArrayList<String> pos17 = new ArrayList<String> ();
    ArrayList<String> word17 = new ArrayList<String> ();
    ArrayList<String> iob18 = new ArrayList<String> ();
    ArrayList<String> pos18 = new ArrayList<String> ();
    ArrayList<String> word18 = new ArrayList<String> ();
    ArrayList<String> iob19 = new ArrayList<String> ();
    ArrayList<String> pos19 = new ArrayList<String> ();
    ArrayList<String> word19 = new ArrayList<String> ();
    ArrayList<String> iob20 = new ArrayList<String> ();
    ArrayList<String> pos20 = new ArrayList<String> ();
    ArrayList<String> word20 = new ArrayList<String> ();

    ArrayList<String> currentchunk = new ArrayList<String>();
    ArrayList<String> currentchunk2 = new ArrayList<String>();
    ArrayList<String> currentchunk3 = new ArrayList<String>();
    ArrayList<String> currentchunk4 = new ArrayList<String>();
    ArrayList<String> currentchunk5 = new ArrayList<String>();
    ArrayList<String> currentchunk6 = new ArrayList<String>();
    ArrayList<String> currentchunk7 = new ArrayList<String>();
    ArrayList<String> currentchunk8 = new ArrayList<String>();
    ArrayList<String> currentchunk9 = new ArrayList<String>();
    ArrayList<String> currentchunk10 = new ArrayList<String>();
    ArrayList<String> currentchunk11 = new ArrayList<String>();
    ArrayList<String> currentchunk12 = new ArrayList<String>();
    ArrayList<String> currentchunk13 = new ArrayList<String>();
    ArrayList<String> currentchunk14 = new ArrayList<String>();
    ArrayList<String> currentchunk15 = new ArrayList<String>();
    ArrayList<String> currentchunk16 = new ArrayList<String>();
    ArrayList<String> currentchunk17 = new ArrayList<String>();
    ArrayList<String> currentchunk18 = new ArrayList<String>();
    ArrayList<String> currentchunk19 = new ArrayList<String>();
    ArrayList<String> currentchunk20 = new ArrayList<String>();

    try
    {
    StreamTokenizer token = new StreamTokenizer(new FileReader(filename[i]));
    //StreamTokenizer token = new StreamTokenizer(new FileReader("008.txt"));
    token.resetSyntax();
    token.ordinaryChar(' ');
    token.wordChars(33,126);
    token.wordChars(48,57);
    //token.quoteChar(9);


    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    // System.out.println(token.sval);
    iob.add(token.sval);
    currentchunk.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos.add("P");
    else
    pos.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word.add(token.sval);
    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {

    each_sentence.add(iob);
    each_sentence.add(pos);
    each_sentence.add(word);
    each_sentence.add(currentchunk);
    sentences.add(each_sentence);
    sentencecount++;
    // System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob2.add(token.sval);
    currentchunk2.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk))pos2.add("P");
    else
    pos2.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word2.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence2.add(iob2);
    each_sentence2.add(pos2);
    each_sentence2.add(word2);
    each_sentence2.add(currentchunk2);
    sentences.add(each_sentence2);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob3.add(token.sval);
    currentchunk3.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk))
    pos3.add("P");
    else
    pos3.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word3.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence3.add(iob3);
    each_sentence3.add(pos3);
    each_sentence3.add(word3);
    each_sentence3.add(currentchunk3);
    sentences.add(each_sentence3);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob4.add(token.sval);
    currentchunk4.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk))pos4.add("P");
    else
    pos4.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word4.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence4.add(iob4);
    each_sentence4.add(pos4);
    each_sentence4.add(word4);
    each_sentence4.add(currentchunk4);
    sentences.add(each_sentence4);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob5.add(token.sval);
    currentchunk5.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk))pos5.add("P");
    else
    pos5.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word5.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence5.add(iob5);
    each_sentence5.add(pos5);
    each_sentence5.add(word5);
    each_sentence5.add(currentchunk5);
    sentences.add(each_sentence5);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob6.add(token.sval);
    currentchunk6.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk))pos6.add("P");
    else
    pos6.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word6.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence6.add(iob6);
    each_sentence6.add(pos6);
    each_sentence6.add(word6);
    each_sentence6.add(currentchunk6);
    sentences.add(each_sentence6);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob7.add(token.sval);
    currentchunk7.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos7.add("P");
    else
    pos7.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word7.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence7.add(iob7);
    each_sentence7.add(pos7);
    each_sentence7.add(word7);
    each_sentence7.add(currentchunk7);
    sentences.add(each_sentence7);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob8.add(token.sval);
    currentchunk8.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos8.add("P");
    else
    pos8.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word8.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence8.add(iob8);
    each_sentence8.add(pos8);
    each_sentence8.add(word8);
    each_sentence8.add(currentchunk8);
    sentences.add(each_sentence8);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob9.add(token.sval);
    currentchunk9.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos9.add("P");
    else
    pos9.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word9.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence9.add(iob9);
    each_sentence9.add(pos9);
    each_sentence9.add(word9);
    each_sentence9.add(currentchunk9);
    sentences.add(each_sentence9);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob10.add(token.sval);
    currentchunk10.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos10.add("P");
    else
    pos10.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word10.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence10.add(iob10);
    each_sentence10.add(pos10);
    each_sentence10.add(word10);
    each_sentence10.add(currentchunk10);
    sentences.add(each_sentence10);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}
    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob11.add(token.sval);
    currentchunk11.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos11.add("P");
    else
    pos11.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word11.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence11.add(iob11);
    each_sentence11.add(pos11);
    each_sentence11.add(word11);
    each_sentence11.add(currentchunk11);
    sentences.add(each_sentence11);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob12.add(token.sval);
    currentchunk12.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos12.add("P");
    else
    pos12.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word12.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence12.add(iob12);
    each_sentence12.add(pos12);
    each_sentence12.add(word12);
    each_sentence12.add(currentchunk12);
    //if(each_sentence == null) break;
    sentences.add(each_sentence12);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob13.add(token.sval);
    currentchunk13.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos13.add("P");
    else
    pos13.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word13.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence13.add(iob13);
    each_sentence13.add(pos13);
    each_sentence13.add(word13);
    each_sentence13.add(currentchunk13);
    sentences.add(each_sentence13);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob14.add(token.sval);
    currentchunk14.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos14.add("P");
    else
    pos14.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word14.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence14.add(iob14);
    each_sentence14.add(pos14);
    each_sentence14.add(word14);
    each_sentence14.add(currentchunk14);
    sentences.add(each_sentence14);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob15.add(token.sval);
    currentchunk15.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos15.add("P");
    else
    pos15.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word15.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence15.add(iob15);
    each_sentence15.add(pos15);
    each_sentence15.add(word15);
    each_sentence15.add(currentchunk15);
    sentences.add(each_sentence15);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}
    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob16.add(token.sval);
    currentchunk16.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos16.add("P");
    else
    pos16.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word16.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence16.add(iob16);
    each_sentence16.add(pos16);
    each_sentence16.add(word16);
    each_sentence16.add(currentchunk16);
    sentences.add(each_sentence16);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob17.add(token.sval);
    currentchunk17.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos17.add("P");
    else
    pos17.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word17.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence17.add(iob17);
    each_sentence17.add(pos17);
    each_sentence17.add(word17);
    each_sentence17.add(currentchunk17);
    sentences.add(each_sentence17);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob18.add(token.sval);
    currentchunk18.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos18.add("P");
    else
    pos18.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word18.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence18.add(iob18);
    each_sentence18.add(pos18);
    each_sentence18.add(word18);
    each_sentence18.add(currentchunk18);
    sentences.add(each_sentence18);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob19.add(token.sval);
    currentchunk19.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos19.add("P");
    else
    pos19.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word19.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence19.add(iob19);
    each_sentence19.add(pos19);
    each_sentence19.add(word19);
    each_sentence19.add(currentchunk19);
    sentences.add(each_sentence19);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}

    while(token.nextToken()!= StreamTokenizer.TT_EOF)
    {
    if(token.ttype==StreamTokenizer.TT_WORD)
    {
    //System.out.println(token.sval);
    iob20.add(token.sval);
    currentchunk20.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    String punc = token.sval;
    if (punc.matches(punk)) pos20.add("P");
    else
    pos20.add(token.sval);
    token.nextToken();
    token.nextToken();
    token.nextToken();
    word20.add(token.sval);

    // System.out.println(word.get(2));
    }

    if(token.ttype ==StreamTokenizer.TT_EOL)
    {
    if(token.nextToken()==StreamTokenizer.TT_EOL)
    {
    each_sentence20.add(iob20);
    each_sentence20.add(pos20);
    each_sentence20.add(word20);
    each_sentence20.add(currentchunk20);
    sentences.add(each_sentence20);
    sentencecount++;
    //System.out.println(sentences.get(sentencecount-1));
    break;
    // iob.clear();
    // pos.clear();
    // word.clear();
    // System.out.println(sentences.get(sentencecount-1));
    }
    else
    token.pushBack();
    }}



    // System.out.println(sentences.get(sentencecount-1));
    } catch (IOException e) {}





    }

    //for(int p=0;p<sentencecount;p++)System.out.println(sentenc es.get(p));
    //System.out.println(sentencecount);

    // System.out.println( ((List) sentences.get(0).get(0)).get(0) ); //gets the 1st IOB tag of the 1st sentence
    // System.out.println( ((List) sentences.get(0).get(1)).get(0) ); //gets the 1st POS tag of the 1st sentence
    // System.out.println( ((List) sentences.get(0).get(2)).get(0) ); //gets the 1st word of the 1st sentence
    // System.out.println( ((List) sentences.get(1).get(0)).get(0) ); //gets the 1st IOB tag of the 2nd sentence

    // System.out.println( ((List) sentences.get(sentencecount-1).get(1)).size() );



    Hashtable posCount = new Hashtable();
    Hashtable temp;

    //String punk = "[^0-9a-zA-Z].*";
    String posTag = " ";

    //Read through the pos tags and their corresponding chunks
    for (int p = 0; p < sentences.size(); p++) {

    for(int q = 0; q< ((List) sentences.get(p).get(0)).size() ;q++){

    // System.out.println(((List) sentences.get(p).get(0)).size());
    temp = new Hashtable();
    posTag = (String) ( (List) sentences.get(p).get(1) ).get(q);
    //if(posTag.matches(punk)){
    //posTag = "P";

    // }

    if(posCount.containsKey(posTag)) { //POS entry exists
    temp = (Hashtable)posCount.get(posTag);

    if(temp.containsKey(((List) sentences.get(p).get(0)).get(q))) { //Chunk entry exists
    Integer n = (Integer)temp.get(((List) sentences.get(p).get(0)).get(q));
    int m = n.intValue();
    m++; //one more entry of this chunk
    temp.put(((List) sentences.get(p).get(0)).get(q), new Integer(m));
    posCount.put(posTag, temp);
    }
    else { //Chunk entry does not exist, we create it
    temp.put(((List) sentences.get(p).get(0)).get(q), new Integer(1));
    posCount.put(posTag, temp);
    }
    }
    else { //POS entry does not exist, hence we create one;
    temp.put(((List) sentences.get(p).get(0)).get(q), new Integer(1));
    posCount.put(posTag, temp);
    }
    }
    }


    //Now we do the counting
    String tempS;
    String chunkTag = " ";
    Integer n;
    int count=0;
    temp = new Hashtable(); //Re-used from above
    Enumeration enumPOS, enumChunk;
    Hashtable probtags = new Hashtable();

    enumPOS = posCount.keys(); //Get all the POS keys
    while(enumPOS.hasMoreElements()) {
    count = 0;
    posTag = (String)enumPOS.nextElement();
    temp = (Hashtable)posCount.get(posTag);

    enumChunk = temp.keys(); //Get all the chunk keys
    while(enumChunk.hasMoreElements()) {
    tempS = (String)enumChunk.nextElement();
    n = (Integer)temp.get(tempS);
    if (n.intValue() >= count) { //NOTE >=
    count = n.intValue();
    chunkTag = tempS;
    }
    }

    //Now simply output the result
    // System.out.println("The most highest count for POS tag " + posTag + " is Chunk tag " + chunkTag + " at value " + count);
    probtags.put(posTag,chunkTag);
    }



    //System.out.println();

    for(int r = 0; r<sentences.size(); r++)
    {
    for(int s = 0; s< ((List) sentences.get(r).get(0)).size() ;s++)
    {
    //( (List) ((List)sentences.get(r).get(3) ).get(s)). add (
    // if(probtags.get( (( (List) sentences.get(r).get(0) ).get(s))) == null);
    // System.out.println((( (List) sentences.get(r).get(0) ).get(s)));

    // System.out.println( ((List) (sentences.get(r).get(3))).get(s) );
    // System.out.println( ((List) (sentences.get(r).get(0))).get(s) );

    // System.out.println( probtags.get( ((List) (sentences.get(r).get(1))).get(s)) ) ; //printing every probtags of rth sentence

    //now i need change the currenttag to the probtags

    String tempprobtag = (String) probtags.get( ((List) (sentences.get(r).get(1))).get(s));



    //((List)(((List) (sentences.get(r).get(3))).get(s) )).set(s,(String)tempprobtag);

    ArrayList<String> test = new ArrayList<String> ();
    List<List> test2 = new ArrayList<List>();
    List<List> test3 = new ArrayList<List>();


    test.add("pig");
    test2.add(test);
    test3.add(test2);

    System.out.println( ((List) ((List)(test3.get(0).get(0))).get(0)) .set(0,"cow") );

    // System.out.println(test.get(0));



    }



    }







    }

    }

  14. #14
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    My Sentence class is simply a struct.
    If you make the fields public, you can use it exactly like a struct.
    That is not good OO, but it works.

    What in the world are you doing with this code?
    Java Code:
    for(int i=0; i<100; i++)
    {
    
    List<List> each_sentence = new ArrayList<List>();
    List<List> each_sentence2 = new ArrayList<List>();
    List<List> each_sentence3 = new ArrayList<List>();
    List<List> each_sentence4 = new ArrayList<List>();
    You are not using the 'i' variable.
    You should not have 20 lines of duplicated code. That is evil.

    Really, drop back, think about what you want to do.
    You would not have such an ugly amount of duplicated code in C.
    Don't do it in Java.

  15. #15
    alvations is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default

    i tried using one List<List> each_sentence

    then i put then in List<List>sentences.

    but i need to clear ArrayList<string> word, after reading eachsentences and when i did that it clears my element in List<List> sentences. i can't get a way to deepcopy it into the List<List>.

    so in the end i hardcode it to read individual textfile for 20 sentences,

    each text file looks liek this
    ____________________________

    B-NP DT A
    I-NP NN form
    B-PP IN of
    B-NP NN asbestos
    B-ADVP RB once
    B-VP VBN used
    B-VP TO to
    I-VP VB make
    B-NP NNP Kent
    I-NP NN cigarette
    I-NP NNS filters
    B-VP VBZ has
    I-VP VBN caused
    B-NP DT a
    I-NP JJ high
    I-NP NN percentage
    B-PP IN of
    B-NP NN cancer
    I-NP NNS deaths
    B-PP IN among
    B-NP DT a
    I-NP NN group
    B-PP IN of
    B-NP NNS workers
    B-VP VBN exposed
    B-PP TO to
    B-NP PRP it
    B-NP RBR more
    I-NP IN than
    I-NP CD 30
    I-NP NNS years
    B-ADVP IN ago
    O COMMA COMMA
    B-NP NNS researchers
    B-VP VBD reported
    O . .

    B-NP DT The
    I-NP NN asbestos
    I-NP NN fiber
    O COMMA COMMA
    B-NP NN crocidolite
    O COMMA COMMA
    B-VP VBZ is
    B-ADJP RB unusually
    I-ADJP JJ resilient
    B-SBAR IN once
    B-NP PRP it
    B-VP VBZ enters
    B-NP DT the
    I-NP NNS lungs
    O COMMA COMMA
    B-PP IN with
    B-NP RB even
    I-NP JJ brief
    I-NP NNS exposures
    B-PP TO to
    B-NP PRP it
    B-VP VBG causing
    B-NP NNS symptoms
    B-NP WDT that
    B-VP VBP show
    B-PRT RP up
    B-NP NNS decades
    B-ADVP JJ later
    O COMMA COMMA
    B-NP NNS researchers
    B-VP VBD said
    O . .

    B-NP NNP Lorillard
    I-NP NNP Inc.
    O COMMA COMMA
    B-NP DT the
    I-NP NN unit
    B-PP IN of
    B-NP JJ New
    I-NP JJ York-based
    I-NP NNP Loews
    I-NP NNP Corp.
    B-NP WDT that
    B-VP VBZ makes
    B-NP NNP Kent
    I-NP NNS cigarettes
    O COMMA COMMA
    B-VP VBD stopped
    I-VP VBG using
    B-NP NN crocidolite
    B-PP IN in
    B-NP PRP$ its
    I-NP NN Micronite
    I-NP NN cigarette
    I-NP NNS filters
    B-PP IN in
    B-NP CD 1956
    O . .

    B-SBAR IN Although
    B-NP JJ preliminary
    I-NP NNS findings
    B-VP VBD were
    I-VP VBN reported
    B-NP RBR more
    I-NP IN than
    I-NP DT a
    I-NP NN year
    B-ADVP IN ago
    O COMMA COMMA
    B-NP DT the
    I-NP JJS latest
    I-NP NNS results
    B-VP VBP appear
    B-PP IN in
    B-NP NN today
    B-NP POS 's
    I-NP NNP New
    I-NP NNP England
    I-NP NNP Journal
    B-PP IN of
    B-NP NNP Medicine
    O COMMA COMMA
    B-NP DT a
    I-NP NN forum
    B-ADJP JJ likely
    B-VP TO to
    I-VP VB bring
    B-NP JJ new
    I-NP NN attention
    B-PP TO to
    B-NP DT the
    I-NP NN problem
    O . .

    B-NP DT A
    I-NP NNP Lorillard
    I-NP NN spokewoman
    B-VP VBD said
    O COMMA COMMA
    O `` ``
    B-NP DT This
    B-VP VBZ is
    B-NP DT an
    I-NP JJ old
    I-NP NN story
    O . .

    B-NP PRP We
    B-VP VBP 're
    I-VP VBG talking
    B-PP IN about
    B-NP NNS years
    B-ADVP IN ago
    B-SBAR IN before
    B-NP NN anyone
    B-VP VBD heard
    B-PP IN of
    B-NP NN asbestos
    B-VP VBG having
    B-NP DT any
    I-NP JJ questionable
    I-NP NNS properties
    O . .

    B-NP EX There
    B-VP VBZ is
    B-NP DT no
    I-NP NN asbestos
    B-PP IN in
    B-NP PRP$ our
    I-NP NNS products
    B-ADVP RB now
    O . .
    O '' ''

    B-NP DT Neither
    B-NP NNP Lorillard
    O CC nor
    B-NP DT the
    I-NP NNS researchers
    B-NP WP who
    B-VP VBD studied
    B-NP DT the
    I-NP NNS workers
    B-VP VBD were
    B-ADJP JJ aware
    B-PP IN of
    B-NP DT any
    I-NP NN research
    B-PP IN on
    B-NP NNS smokers
    B-PP IN of
    B-NP DT the
    I-NP NNP Kent
    I-NP NNS cigarettes
    O . .

    O `` ``
    B-NP PRP We
    B-VP VBP have
    B-NP DT no
    I-NP JJ useful
    I-NP NN information
    B-PP IN on
    B-SBAR IN whether
    B-NP NNS users
    B-VP VBP are
    B-PP IN at
    B-NP NN risk
    O COMMA COMMA
    O '' ''
    B-VP VBD said
    B-NP NNP James
    I-NP NNP A.
    I-NP NNP Talcott
    B-PP IN of
    B-NP NNP Boston
    B-NP POS 's
    I-NP NNP Dana-Farber
    I-NP NNP Cancer
    I-NP NNP Institute
    O . .

    B-NP NNP Dr.
    I-NP NNP Talcott
    B-VP VBD led
    B-NP DT a
    I-NP NN team
    B-PP IN of
    B-NP NNS researchers
    B-PP IN from
    B-NP DT the
    I-NP NNP National
    I-NP NNP Cancer
    I-NP NNP Institute
    O CC and
    B-NP DT the
    I-NP JJ medical
    I-NP NNS schools
    B-PP IN of
    B-NP NNP Harvard
    I-NP NNP University
    O CC and
    B-NP NNP Boston
    I-NP NNP University
    O . .

    B-NP DT The
    I-NP NNP Lorillard
    I-NP NN spokeswoman
    B-VP VBD said
    B-NP NN asbestos
    B-VP VBD was
    I-VP VBN used
    B-PP IN in
    O `` ``
    B-NP RB very
    I-NP JJ modest
    I-NP NNS amounts
    O '' ''
    B-PP IN in
    B-VP VBG making
    B-NP NN paper
    B-PP IN for
    B-NP DT the
    I-NP NNS filters
    B-PP IN in
    B-NP DT the
    I-NP JJ early
    I-NP CD 1950s
    O CC and
    B-VP VBN replaced
    B-PP IN with
    B-NP DT a
    I-NP JJ different
    I-NP NN type
    B-PP IN of
    B-NP NN filter
    B-PP IN in
    B-NP CD 1956
    O . .

    B-PP IN From
    B-NP CD 1953
    B-PP TO to
    B-NP CD 1955
    O COMMA COMMA
    B-NP CD 9.8
    I-NP CD billion
    I-NP NNP Kent
    I-NP NNS cigarettes
    B-PP IN with
    B-NP DT the
    I-NP NNS filters
    B-VP VBD were
    I-VP VBN sold
    O COMMA COMMA
    B-NP DT the
    I-NP NN company
    B-VP VBD said
    O . .

    B-PP IN Among
    B-NP CD 33
    I-NP NNS men
    B-NP WP who
    B-VP VBD worked
    B-ADVP RB closely
    B-PP IN with
    B-NP DT the
    I-NP NN substance
    O COMMA COMMA
    B-NP CD 28
    B-VP VBP have
    I-VP VBN died
    O : --
    B-NP JJ more
    I-NP IN than
    I-NP CD three
    I-NP NNS times
    I-NP DT the
    I-NP VBN expected
    I-NP NN number
    O . .

    B-NP CD Four
    B-PP IN of
    B-NP DT the
    I-NP CD five
    I-NP VBG surviving
    I-NP NNS workers
    B-VP VBP have
    B-NP JJ asbestos-related
    I-NP NNS diseases
    O COMMA COMMA
    B-PP VBG including
    B-NP CD three
    B-PP IN with
    B-NP RB recently
    I-NP VBN diagnosed
    I-NP NN cancer
    O . .

    B-NP DT The
    I-NP NN total
    B-PP IN of
    B-NP CD 18
    I-NP NNS deaths
    B-PP IN from
    B-NP JJ malignant
    I-NP NN mesothelioma
    O COMMA COMMA
    B-NP NN lung
    I-NP NN cancer
    O CC and
    B-NP NN asbestosis
    B-VP VBD was
    B-ADJP RB far
    I-ADJP JJR higher
    B-SBAR IN than
    B-VP VBN expected
    O COMMA COMMA
    B-NP DT the
    I-NP NNS researchers
    B-VP VBD said
    O . .

    O `` ``
    B-NP DT The
    I-NP NN morbidity
    I-NP NN rate
    B-VP VBZ is
    B-NP DT a
    I-NP JJ striking
    I-NP NN finding
    B-PP IN among
    B-NP DT those
    B-PP IN of
    B-NP PRP us
    B-NP WP who
    B-VP VBP study
    B-NP JJ asbestos-related
    I-NP NNS diseases
    O COMMA COMMA
    O '' ''
    B-VP VBD said
    B-NP NNP Dr.
    I-NP NNP Talcott
    O . .

    B-NP DT The
    I-NP NN percentage
    B-PP IN of
    B-NP NN lung
    I-NP NN cancer
    I-NP NNS deaths
    B-PP IN among
    B-NP DT the
    I-NP NNS workers
    B-PP IN at
    B-NP DT the
    I-NP NNP West
    I-NP NNP Groton
    I-NP COMMA COMMA
    I-NP NNP Mass.
    I-NP COMMA COMMA
    I-NP NN paper
    I-NP NN factory
    B-VP VBZ appears
    I-VP TO to
    I-VP VB be
    B-NP DT the
    I-NP JJS highest
    B-PP IN for
    B-NP DT any
    I-NP NN asbestos
    I-NP NNS workers
    B-VP VBN studied
    B-PP IN in
    B-NP JJ Western
    I-NP VBN industrialized
    I-NP NNS countries
    O COMMA COMMA
    B-NP PRP he
    B-VP VBD said
    O . .

    B-NP DT The
    I-NP NN plant
    O COMMA COMMA
    B-NP WDT which
    B-VP VBZ is
    I-VP VBN owned
    B-PP IN by
    B-NP NNP Hollingsworth
    I-NP CC &
    I-NP NNP Vose
    I-NP NNP Co.
    O COMMA COMMA
    B-VP VBD was
    B-PP IN under
    B-NP NN contract
    B-PP IN with
    B-NP NN Lorillard
    B-VP TO to
    I-VP VB make
    B-NP DT the
    I-NP NN cigarette
    I-NP NNS filters
    O . .

    B-NP DT The
    I-NP NN finding
    B-ADVP RB probably
    B-VP MD will
    I-VP VB support
    B-NP DT those
    B-NP WP who
    B-VP VBP argue
    B-SBAR IN that
    B-NP DT the
    I-NP NNP U.S.
    B-VP MD should
    I-VP VB regulate
    B-NP DT the
    I-NP NN class
    B-PP IN of
    B-NP NN asbestos
    B-PP VBG including
    B-NP NN crocidolite
    B-ADVP RBR more
    I-ADVP RB stringently
    B-PP IN than
    B-NP DT the
    I-NP JJ common
    I-NP NN kind
    B-PP IN of
    B-NP NN asbestos
    O COMMA COMMA
    B-NP NN chrysotile
    O COMMA COMMA
    B-VP VBN found
    B-PP IN in
    B-NP JJS most
    I-NP NNS schools
    O CC and
    B-NP JJ other
    I-NP NNS buildings
    O COMMA COMMA
    B-NP NNP Dr.
    I-NP NNP Talcott
    B-VP VBD said
    O . .

    B-NP DT The
    I-NP NNP U.S.
    B-VP VBZ is
    B-NP CD one
    B-PP IN of
    B-NP DT the
    I-NP JJ few
    I-NP VBN industrialized
    I-NP NNS nations
    B-NP WDT that
    B-VP VBZ does
    I-VP RB n't
    I-VP VB have
    B-NP DT a
    I-NP JJR higher
    I-NP NN standard
    B-PP IN of
    B-NP NN regulation
    B-PP IN for
    B-NP DT the
    I-NP JJ smooth
    I-NP COMMA COMMA
    I-NP JJ needle-like
    I-NP NNS fibers
    B-PP JJ such
    I-PP IN as
    B-NP NN crocidolite
    B-NP WDT that
    B-VP VBP are
    I-VP VBN classified
    B-PP IN as
    B-NP NNS amphobiles
    O COMMA COMMA
    B-PP VBG according
    B-PP TO to
    B-NP NNP Brooke
    I-NP NNP T.
    I-NP NNP Mossman
    O COMMA COMMA
    B-NP DT a
    I-NP NN professor
    B-PP IN of
    B-NP NN pathlogy
    B-PP IN at
    O DT the
    O NNP University
    B-PP IN of
    B-NP NNP Vermont
    B-NP NNP College
    B-PP IN of
    B-NP NNP Medicine
    O . .

    B-NP RBR More
    I-NP JJ common
    I-NP NN chrysotile
    I-NP NNS fibers
    B-VP VBP are
    B-ADJP JJ curly
    O CC and
    B-VP VBP are
    I-VP RBR more
    I-VP RB easily
    I-VP VBN rejected
    B-PP IN by
    B-NP DT the
    I-NP NN body
    O COMMA COMMA
    B-NP NNP Dr.
    I-NP NNP Mossman
    B-VP VBD explained
    O . .

    B-PP IN In
    B-NP NNP July
    O COMMA COMMA
    B-NP DT the
    I-NP NNP Environmental
    I-NP NNP Protection
    I-NP NNP Agency
    B-VP VBD imposed
    B-NP DT a
    I-NP JJ gradual
    I-NP NN ban
    B-PP IN on
    B-NP RB virtually
    I-NP DT all
    I-NP NNS uses
    B-PP IN of
    B-NP NN asbestos
    O . .

    B-PP IN By
    B-NP CD 1997
    O COMMA COMMA
    B-NP RB almost
    I-NP DT all
    I-NP VBG remaining
    I-NP NNS uses
    B-PP IN of
    B-NP JJ cancer-causing
    I-NP NN asbestos
    B-VP MD will
    I-VP VB be
    I-VP VBN outlawed
    O . .

    B-NP IN About
    I-NP CD 160
    I-NP NNS workers
    B-PP IN at
    B-NP DT a
    I-NP NN factory
    B-NP WDT that
    B-VP VBD made
    B-NP NN paper
    B-PP IN for
    B-NP DT the
    I-NP NNP Kent
    I-NP NNS filters
    B-VP VBD were
    I-VP VBN exposed
    B-PP TO to
    B-NP NN asbestos
    B-PP IN in
    B-NP DT the
    I-NP CD 1950s
    O . .

    B-NP NNS Areas
    B-PP IN of
    B-NP DT the
    I-NP NN factory
    B-VP VBD were
    B-ADJP RB particularly
    I-ADJP JJ dusty
    B-ADVP WRB where
    B-NP DT the
    I-NP NN crocidolite
    B-VP VBD was
    I-VP VBN used
    O . .

    B-NP NNS Workers
    B-VP VBD dumped
    B-NP JJ large
    I-NP NN burlap
    I-NP NNS sacks
    B-PP IN of
    B-NP DT the
    I-NP VBN imported
    I-NP NN material
    B-PP IN into
    B-NP DT a
    I-NP JJ huge
    I-NP NN bin
    O COMMA COMMA
    B-VP VBD poured
    B-PRT RP in
    B-NP NN cotton
    I-NP CC and
    I-NP NN acetate
    I-NP NNS fibers
    O CC and
    B-VP RB mechanically
    I-VP VBD mixed
    B-NP DT the
    I-NP JJ dry
    I-NP NNS fibers
    B-PP IN in
    B-NP DT a
    I-NP NN process
    B-VP VBN used
    B-VP TO to
    I-VP VB make
    B-NP NNS filters
    O . .

    B-NP NNS Workers
    B-VP VBD described
    O `` ``
    B-NP NNS clouds
    B-PP IN of
    B-NP JJ blue
    I-NP NN dust
    O '' ''
    B-NP WDT that
    B-VP VBD hung
    B-PP IN over
    B-NP NNS parts
    B-PP IN of
    B-NP DT the
    I-NP NN factory
    O COMMA COMMA
    B-SBAR RB even
    I-SBAR IN though
    B-NP NN exhaust
    I-NP NNS fans
    B-VP VBD ventilated
    B-NP DT the
    I-NP NN area
    O . .

    O `` ``
    B-NP EX There
    B-VP VBZ 's
    B-NP DT no
    I-NP NN question
    B-SBAR IN that
    B-NP DT some
    B-PP IN of
    B-NP DT those
    I-NP NNS workers
    I-NP CC and
    I-NP NNS managers
    B-VP VBD contracted
    B-NP JJ asbestos-related
    I-NP NNS diseases
    O COMMA COMMA
    O '' ''
    B-VP VBD said
    B-NP NNP Darrell
    I-NP NNP Phillips
    O COMMA COMMA
    B-NP NN vice
    I-NP NN president
    B-PP IN of
    B-NP JJ human
    I-NP NNS resources
    B-PP IN for
    B-NP NNP Hollingsworth
    I-NP CC &
    I-NP NNP Vose
    O . .

    O `` ``
    O CC But
    B-NP PRP you
    B-VP VBP have
    I-VP TO to
    I-VP VB recognize
    B-SBAR IN that
    B-NP DT these
    I-NP NNS events
    B-VP VBD took
    B-NP NN place
    B-NP CD 35
    I-NP NNS years
    B-ADVP IN ago
    O . .

    B-NP PRP It
    B-VP VBZ has
    B-NP DT no
    I-NP NN bearing
    B-PP IN on
    B-NP PRP$ our
    I-NP NN work
    I-NP NN force
    B-NP NN today
    O . .

    _____________________________________

    i guess the only way for me to change "pig" to "cow" is to recode. hahhaa. but i only have 2 days till my deadline. hahaha. i'll try.

    still have 2 modules to integrate.

  16. #16
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by alvations View Post
    i guess the only way for me to change "pig" to "cow" is to recode. hahhaa. but i only have 2 days till my deadline. hahaha. i'll try.
    The normal way to change pig to cow is to
    do something like:

    Sentence pigS = listOSentences.indexOf("pig");
    pigS.setType("cow");

    But this is not real code, its just conceptual. If you are going to do it with any frequency, you want to setup a Comparable array, or implement a Comparator

    You should look at the Collections tutorial.
    Trail: Collections (The Java™ Tutorials)

Similar Threads

  1. List and ArrayList
    By ravian in forum New To Java
    Replies: 3
    Last Post: 07-27-2011, 05:05 PM
  2. deep copying arraylist to add to a list
    By alvations in forum New To Java
    Replies: 13
    Last Post: 10-08-2008, 03:13 PM
  3. How to access ArrayList in List of List?
    By alvations in forum New To Java
    Replies: 5
    Last Post: 10-08-2008, 12:23 PM
  4. [SOLVED] Creating List of Values Using ClipBoard Object
    By Judoon_Platoon in forum Java Applets
    Replies: 2
    Last Post: 05-21-2008, 08:07 AM
  5. Getting values of an Option List
    By mutuah in forum Advanced Java
    Replies: 0
    Last Post: 08-07-2007, 03:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •