public static void clearPredictions(Data data) { for (int docid = 0; docid < data.documents.size(); docid++) { ArrayList<LinkedVector> sentences = data.documents.get(docid).sentences; for (LinkedVector sentence : sentences) { for (int i = 0; i < sentence.size(); i++) { ((NEWord) sentence.get(i)).neTypeLevel1 = null; ((NEWord) sentence.get(i)).neTypeLevel2 = null; } } } } }
/** * Given a {@link LinkedVector} containing {@link Word}s, this method * creates a new {@link LinkedVector} containing {@link Token}s. * * @param v A {@link LinkedVector} of {@link Word}s. * @return A {@link LinkedVector} of {@link Token}s corresponding to the * input {@link Word}s. **/ public static LinkedVector convert(LinkedVector v) { if (v == null) return null; if (v.size() == 0) return v; Word w = (Word) v.get(0); Token t = new Token(w, null, null); for (w = (Word) w.next; w != null; w = (Word) w.next) { t.next = new Token(w, t, null); t = (Token) t.next; } return new LinkedVector(t); }
/** * Constructor for when only a single child from anywhere in this vector is available. It is * assumed that the <code>previous</code> and <code>next</code> links are filled in by every * child. * * @param c Any child in this vector. * @param s The offset at which this sentence starts. * @param e The offset at which this sentence ends. **/ public LinkedVector(LinkedChild c, int s, int e) { super(s, e); children = new Vector(); while (c.previous != null) c = c.previous; for (; c != null; c = c.next) add(c); }
/** * Returns a clone of this object that is deep in the sense that all of the children objects are * cloned. * * @return A deep clone of this object. **/ public Object clone() { LinkedVector clone = (LinkedVector) super.clone(); clone.children = (Vector) clone.children.clone(); // This may look inefficient, but there is a purpose. Subclasses of // LinkedVector that don't define any new non-primitive member fields will // not need to override this method, as it already produces an object of // the subclass's type. for (int i = 0; i < size(); ++i) clone.insert((LinkedChild) clone.remove(i).clone(), i); return clone; } }
ArrayList<LinkedVector> clonedSentences = new ArrayList<>(); for (LinkedVector originalSentence : originalSentences) { LinkedVector sentence = new LinkedVector(); for (int j = 0; j < originalSentence.size(); j++) { NEWord originalW = (NEWord) originalSentence.get(j); NEWord w = new NEWord(new Word(originalW.form), null, null); w.neLabel = originalW.neLabel; .substring(2))) w.neTypeLevel2 = w.neTypeLevel2.substring(0, 2) + "ENTITY"; sentence.add(w); dataCloneWithanonymizedLabels.documents.get(docid).sentences; for (LinkedVector vector : sentences) { int N = vector.size(); String[] predictionsLevel1 = new String[N], predictionsLevel2 = new String[N], labels = new String[N]; predictionsLevel1[i] = ((NEWord) vector.get(i)).neTypeLevel1; predictionsLevel2[i] = ((NEWord) vector.get(i)).neTypeLevel2; labels[i] = labeler.discreteValue(vector.get(i)); String pLevel1 = predictionsLevel1[i]; String pLevel2 = predictionsLevel2[i]; dataCloneWithanonymizedLabels.documents.get(docid).sentences; for (LinkedVector sentence : sentences) for (int j = 0; j < sentence.size(); j++) { NEWord w = (NEWord) sentence.get(j); String bracketTypePrediction = w.neTypeLevel2;
LinkedVector res = new LinkedVector(); NEWord w = new NEWord(new Word(token, pos), null, label); NEWord.addTokenToSentence(res, w.form, w.neLabel, params); NEWord.addTokenToSentence(res, w.form, w.neLabel, params); if (res.size() == 0) return null; return res;
/** * Given an array of <code>String</code>s, this method creates a new * {@link LinkedVector} containing {@link Word}s. * * @param a An array of <code>String</code>s. * @return A {@link LinkedVector} of {@link Word}s corresponding to the * input <code>String</code>s. **/ public static LinkedVector convert(String[] a) { if (a == null) return null; if (a.length == 0) return new LinkedVector(); Word w = new Word(a[0]); for (int i = 1; i < a.length; ++i) { w.next = new Word(a[i], null, w); w = (Word) w.next; } return new LinkedVector(w); }
LinkedVector lbjTokenVectorList = new LinkedVector(); LinkedVector lbjSentenceTokens = new LinkedVector(); lbjTokenVectorList.add( lbjSentenceTokens ); lbjSentenceTokens = new LinkedVector(); wcurrent.partOfSpeech = tokSpan.getLabel(); Token tcurrent = new Token(wcurrent, tprevious, ""); lbjSentenceTokens.add(tcurrent); if (tprevious != null) { tprevious.next = tcurrent; if ( !( lbjSentenceTokens.size() == 0 ) ) // means there is a sentence not added to linkedvector lbjTokenVectorList.add( lbjSentenceTokens );
/** * This method returns {@link Token}s until the input is exhausted, at * which point it returns <code>null</code>. **/ public Object next() { while (next == null) { LinkedVector words = (LinkedVector) parser.next(); if (words == null) return null; Word w = (Word) words.get(0); Token t = new Token(w, null, null); for (w = (Word) w.next; w != null; w = (Word) w.next) { t.next = new Token(w, t, null); t = (Token) t.next; } LinkedVector tokens = new LinkedVector(t); next = (Token) tokens.get(0); } Token result = next; next = (Token) next.next; return result; }
/** * Adds the specified child to the end of the vector, informing the child of its parent and * index and linking the child to its only neighbor (which was previously the last child in the * vector). * * @param c The child to add. **/ public boolean add(LinkedChild c) { c.parent = this; if (children.size() > 0) { LinkedChild p = get(children.size() - 1); p.next = c; c.previous = p; } return children.add(c); }
ArrayList<LinkedVector> clonedSentences = new ArrayList<>(); for (LinkedVector originalSentence : originalSentences) { LinkedVector sentence = new LinkedVector(); for (int j = 0; j < originalSentence.size(); j++) { NEWord originalW = (NEWord) originalSentence.get(j); NEWord w = new NEWord(new Word(originalW.form), null, null); w.neLabel = originalW.neLabel; .substring(2))) w.neTypeLevel2 = w.neTypeLevel2.substring(0, 2) + "ENTITY"; sentence.add(w); dataCloneWithanonymizedLabels.documents.get(docid).sentences; for (LinkedVector vector : sentences) { int N = vector.size(); String[] predictionsLevel1 = new String[N], predictionsLevel2 = new String[N], labels = new String[N]; predictionsLevel1[i] = ((NEWord) vector.get(i)).neTypeLevel1; predictionsLevel2[i] = ((NEWord) vector.get(i)).neTypeLevel2; labels[i] = labeler.discreteValue(vector.get(i)); String pLevel1 = predictionsLevel1[i]; String pLevel2 = predictionsLevel2[i]; dataCloneWithanonymizedLabels.documents.get(docid).sentences; for (LinkedVector sentence : sentences) for (int j = 0; j < sentence.size(); j++) { NEWord w = (NEWord) sentence.get(j); String bracketTypePrediction = w.neTypeLevel2;
LinkedVector res = new LinkedVector(); NEWord w = new NEWord(new Word(token, pos), null, label); NEWord.addTokenToSentence(res, w.form, w.neLabel, params); NEWord.addTokenToSentence(res, w.form, w.neLabel, params); if (res.size() == 0) return null; return res;
/** * Given an array of <code>String</code>s, this method creates a new * {@link LinkedVector} containing {@link Word}s. * * @param a An array of <code>String</code>s. * @return A {@link LinkedVector} of {@link Word}s corresponding to the * input <code>String</code>s. **/ public static LinkedVector convert(String[] a) { if (a == null) return null; if (a.length == 0) return new LinkedVector(); Word w = new Word(a[0]); for (int i = 1; i < a.length; ++i) { w.next = new Word(a[i], null, w); w = (Word) w.next; } return new LinkedVector(w); }
/** * This method returns {@link Token}s until the input is exhausted, at * which point it returns <code>null</code>. **/ public Object next() { while (next == null) { LinkedVector words = (LinkedVector) parser.next(); if (words == null) return null; Word w = (Word) words.get(0); Token t = new Token(w, null, null); for (w = (Word) w.next; w != null; w = (Word) w.next) { t.next = new Token(w, t, null); t = (Token) t.next; } LinkedVector tokens = new LinkedVector(t); next = (Token) tokens.get(0); } Token result = next; next = (Token) next.next; return result; }
/** * Retrieves the next sentence from the files being parsed. * * @return A <code>LinkedVector</code> representation of the next sentence. **/ public Object next() { if (currentWord == null) { LinkedVector vector = (LinkedVector) super.next(); if (vector != null) currentWord = (Word) vector.get(0); } Word result = currentWord; if (currentWord != null) currentWord = (Word) currentWord.next; return result; } }
public static void clearPredictions(Data data) { for (int docid = 0; docid < data.documents.size(); docid++) { ArrayList<LinkedVector> sentences = data.documents.get(docid).sentences; for (LinkedVector sentence : sentences) { for (int i = 0; i < sentence.size(); i++) { ((NEWord) sentence.get(i)).neTypeLevel1 = null; ((NEWord) sentence.get(i)).neTypeLevel2 = null; } } } } }
/** * Given a {@link LinkedVector} containing {@link Word}s, this method * creates a new {@link LinkedVector} containing {@link Token}s. * * @param v A {@link LinkedVector} of {@link Word}s. * @return A {@link LinkedVector} of {@link Token}s corresponding to the * input {@link Word}s. **/ public static LinkedVector convert(LinkedVector v) { if (v == null) return null; if (v.size() == 0) return v; Word w = (Word) v.get(0); Token t = new Token(w, null, null); for (w = (Word) w.next; w != null; w = (Word) w.next) { t.next = new Token(w, t, null); t = (Token) t.next; } return new LinkedVector(t); }
ArrayList<LinkedVector> clonedSentences = new ArrayList<>(); for (LinkedVector originalSentence : originalSentences) { LinkedVector sentence = new LinkedVector(); for (int j = 0; j < originalSentence.size(); j++) { NEWord originalW = (NEWord) originalSentence.get(j); NEWord w = new NEWord(new Word(originalW.form), null, null); w.neLabel = originalW.neLabel; .substring(2))) w.neTypeLevel2 = w.neTypeLevel2.substring(0, 2) + "ENTITY"; sentence.add(w); dataCloneWithanonymizedLabels.documents.get(docid).sentences; for (LinkedVector vector : sentences) { int N = vector.size(); String[] predictionsLevel1 = new String[N], predictionsLevel2 = new String[N], labels = new String[N]; predictionsLevel1[i] = ((NEWord) vector.get(i)).neTypeLevel1; predictionsLevel2[i] = ((NEWord) vector.get(i)).neTypeLevel2; labels[i] = labeler.discreteValue(vector.get(i)); String pLevel1 = predictionsLevel1[i]; String pLevel2 = predictionsLevel2[i]; dataCloneWithanonymizedLabels.documents.get(docid).sentences; for (LinkedVector sentence : sentences) for (int j = 0; j < sentence.size(); j++) { NEWord w = (NEWord) sentence.get(j); String bracketTypePrediction = w.neTypeLevel2;
LinkedVector res = new LinkedVector(); NEWord w = new NEWord(new Word(token, pos), null, label); NEWord.addTokenToSentence(res, w.form, w.neLabel); NEWord.addTokenToSentence(res, w.form, w.neLabel); if (res.size() == 0) return null; return res;
public static ArrayList<LinkedVector> parseText(String text, ParametersForLbjCode cp) { Vector<Vector<String>> processed = sentenceSplitAndTokenizeText(text, cp); ArrayList<LinkedVector> res = new ArrayList<>(); for (int i = 0; i < processed.size(); i++) { LinkedVector sentence = new LinkedVector(); for (int j = 0; j < processed.elementAt(i).size(); j++) NEWord.addTokenToSentence(sentence, processed.elementAt(i).elementAt(j), "unlabeled", cp); res.add(sentence); } TaggedDataReader.connectSentenceBoundaries(res); return res; }