Java Code Examples for it.unimi.dsi.fastutil.objects.ObjectArrayList#clear()
The following examples show how to use
it.unimi.dsi.fastutil.objects.ObjectArrayList#clear() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastUtil.java From minie with GNU General Public License v3.0 | 6 votes |
/** * Given a list of lists, return all the combinations between the lists (i.e. their indices). For example, suppose we * have the list of lists: [[1, 2, 3], [4, 5], [6, 7, 8]]. Then, this function will return: * [[0, 1], [1, 0], [0, 2], [2, 0], [1, 2], [2, 1], * [0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1]] * @param lists: list of lists * @return */ public static <T> ObjectArrayList<IntArrayList> getListsCombinationIndices(ObjectArrayList<ObjectArrayList<T>> lists){ ObjectArrayList<IntArrayList> combinationsInd = new ObjectArrayList<>(); ObjectArrayList<IntArrayList> result = new ObjectArrayList<>(); int[][] combinations; for (int k = 2; k <= lists.size(); k++){ result.clear(); combinations = null; combinations = getCombinations(k, lists.size()); for (int i = 0; i < combinations.length; i++) { IntArrayList indices = new IntArrayList(); for (int j = 0; j < combinations[i].length; j++) { indices.add(combinations[i][j]); } permute(indices, 0, result); } combinationsInd.addAll(result); } return combinationsInd; }
Example 2
Source File: AnnotatedPhrase.java From minie with GNU General Public License v3.0 | 6 votes |
/** * A helper function used in detectQuantities. When we have a list of quantity words, quantity edges and the * sentence semantic graph, add quantities to the list of quantities and clear the reusable lists. * If there are quantities in the phrase, replace them with the word SOME_n_i, where i = the place of the quantity * (0 - subject, 1 - relation, 2 - object) and j = # of quantity within the phrase. * * @param qWords: list of quantity indexed words * @param qEdges: list of semantic graph edges (reusable) * @param sentSemGraph: sentence semantic graph * @param i: used for ID-ying purposes of the quantities' annotations * @param j: used for ID-ying purposes of the quantities' annotations */ private void setQuantitiesFromWordList(ObjectArrayList<IndexedWord> qWords, ObjectArrayList<SemanticGraphEdge> qEdges, SemanticGraph sentSemGraph, int i, int j){ // Quantity ID StringBuilder sbId = new StringBuilder(); if (i == 0) sbId.append(Quantity.SUBJECT_ID); else if (i == 1) sbId.append(Quantity.RELATION_ID); else sbId.append(Quantity.OBJECT_ID); sbId.append(CHARACTER.UNDERSCORE); sbId.append(j + 1); // Indexing starts from 1 for (IndexedWord w: qWords){ qEdges.add(sentSemGraph.getEdge(sentSemGraph.getParent(w), w)); } // Add the quantity to the list this.quantities.add(new Quantity(qWords, qEdges, sbId.toString())); // Clear the lists qWords.clear(); qEdges.clear(); }
Example 3
Source File: Equation.java From WarpPI with Apache License 2.0 | 6 votes |
public ObjectArrayList<Equation> solveStep(final char charIncognita) { ObjectArrayList<Equation> result = new ObjectArrayList<>(); result.add(clone()); for (final SolveMethod t : SolveMethod.techniques) { final ObjectArrayList<Equation> newResults = new ObjectArrayList<>(); final int sz = result.size(); for (int n = 0; n < sz; n++) { newResults.addAll(t.solve(result.get(n))); } final Set<Equation> hs = new HashSet<>(); hs.addAll(newResults); newResults.clear(); newResults.addAll(hs); result = newResults; } // TODO: controllare se รจ a posto return result; }
Example 4
Source File: PagesIndex.java From presto with Apache License 2.0 | 5 votes |
public void clear() { for (ObjectArrayList<Block> channel : channels) { channel.clear(); channel.trim(); } valueAddresses.clear(); valueAddresses.trim(); positionCount = 0; nextBlockToCompact = 0; pagesMemorySize = 0; estimatedSize = calculateEstimatedSize(); }
Example 5
Source File: FastUtil.java From minie with GNU General Public License v3.0 | 5 votes |
/** * Given a list of lists, and a list of lists of integers, which is a combination of indices between the elements of * "lists", get the set of all elements' combinations. For example, if we have a list of the list 'combinationsInd' which is * [1, 2], and the list of lists 'lists' is [[1, 2, 3], [4, 5], [6, 7, 8]], then this function will add the following lists * to the result: [[4, 6], [4, 7], [4, 8], [5, 7], [5, 8]] * @param combinationsInd: list of indices of the lists to be combined * @param lists: list of lists * @return */ public static <T> ObjectOpenHashSet<ObjectArrayList<T>> getListsElementsCombinationSet( ObjectArrayList<IntArrayList> combinationsInd, ObjectArrayList<ObjectArrayList<T>> lists){ ObjectOpenHashSet<ObjectArrayList<T>> combinationSets = new ObjectOpenHashSet<>(); ObjectArrayList<ObjectArrayList<T>> tempLists = new ObjectArrayList<>(); for (IntArrayList indList: combinationsInd){ tempLists.clear(); for (int index: indList){ tempLists.add(lists.get(index)); } combinationSets.addAll(getElementsCombinations(tempLists)); } return combinationSets; }
Example 6
Source File: FastUtil.java From minie with GNU General Public License v3.0 | 5 votes |
/** * Given a list of lists, get the combinations of the elements between the lists. * For example, if we have lists = [[1, 2, 3], [4, 5]], then * getElementsCombinations(lists) = [1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5] * @param lists: list of lists * @return combination of elements between the lists */ public static <T> Set<ObjectArrayList<T>> getElementsCombinations(ObjectArrayList<ObjectArrayList<T>> lists) { Set<ObjectArrayList<T>> combinations = new HashSet<ObjectArrayList<T>>(); Set<ObjectArrayList<T>> newCombinations = new HashSet<ObjectArrayList<T>>(); ObjectArrayList<T> newList = new ObjectArrayList<T>(); int index = 0; // Extract each of the integers in the first list and add each to ints as a new list for(T i: lists.get(0)) { newList.clear(); newList.add(i); combinations.add(newList.clone()); } index++; List<T> nextList; while(index < lists.size()) { nextList = lists.get(index).clone(); newCombinations.clear(); for(List<T> first: combinations) { for(T second: nextList) { newList.clear(); newList.addAll(first); newList.add(second); newCombinations.add(newList.clone()); } } combinations = newCombinations; index++; nextList.clear(); } return combinations; }
Example 7
Source File: ImplicitExtractions.java From minie with GNU General Public License v3.0 | 5 votes |
/** Generate some extractions from TokenRegex patterns **/ public void generateSequentialPatternExtractions() { // Reusable variables ObjectArrayList<AnnotatedPhrase> tempProp = new ObjectArrayList<>(); IndexedWord subjRoot; IndexedWord objRoot; this.tPattern = TokenSequencePattern.compile(REGEX.T_ORG_IN_LOC); this.tMatcher = this.tPattern.getMatcher(CoreNLPUtils.getCoreLabelListFromIndexedWordList(this.sentence)); while (this.tMatcher.find()){ this.setIsARelation(); for (IndexedWord w: CoreNLPUtils.listOfCoreMapWordsToIndexedWordList(this.tMatcher.groupNodes())) { if (w.ner().equals(NE_TYPE.ORGANIZATION)) { this.subj.addWordToList(w); } else if (w.ner().equals(NE_TYPE.LOCATION)) { this.obj.addWordToList(w); } else if (w.ner().equals(NE_TYPE.NO_NER) && w.tag().equals(POS_TAG.IN)) { this.rel.addWordToList(w); } } subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, subj.getWordList()); objRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, obj.getWordList()); tempProp.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot)); tempProp.add(new AnnotatedPhrase(this.rel.getWordList().clone(), this.rel.getRoot())); tempProp.add(new AnnotatedPhrase(this.obj.getWordList().clone(), objRoot)); this.propositions.add(new AnnotatedProposition(tempProp.clone(), new Attribution())); // Clean the variables tempProp.clear(); this.subj.clear(); this.rel.clear(); this.obj.clear(); } }
Example 8
Source File: ImplicitExtractions.java From minie with GNU General Public License v3.0 | 5 votes |
/** If "city|town of LOCATION" => "LOCATION" "is" "city|town" **/ public void extractCityOfLocation() { // Reusable variable ObjectArrayList<AnnotatedPhrase> tempProp = new ObjectArrayList<>(); IndexedWord subjRoot; IndexedWord objRoot; // Set the relation to be "is-a" relation this.setIsARelation(); this.tPattern = TokenSequencePattern.compile(REGEX.T_CITY_OF_LOC); this.tMatcher = tPattern.getMatcher(CoreNLPUtils.getCoreLabelListFromIndexedWordList(this.sentence)); while (this.tMatcher.find()){ ObjectArrayList<IndexedWord> mWords = CoreNLPUtils.listOfCoreMapWordsToIndexedWordList(this.tMatcher.groupNodes()); for (IndexedWord w: mWords) { if (!w.ner().equals(NE_TYPE.LOCATION) && !w.tag().equals(POS_TAG.IN)) this.obj.addWordToList(w); else{ if (!w.tag().equals(POS_TAG.IN)) this.subj.addWordToList(w); } } // Add the subj/rel/obj to the temporary proposition and then to the real propositions subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList()); objRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.obj.getWordList()); tempProp.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot)); tempProp.add(new AnnotatedPhrase(this.rel.getWordList().clone(), this.rel.getRoot())); tempProp.add(new AnnotatedPhrase(this.obj.getWordList().clone(), objRoot)); this.propositions.add(new AnnotatedProposition(tempProp.clone(), new Attribution())); // Clean the variables tempProp.clear(); this.subj.clear(); this.obj.clear(); } // Clear the relation this.rel.clear(); }
Example 9
Source File: CallGraphGenerator.java From fasten with Apache License 2.0 | 4 votes |
private static String graph2String(final CallGraphGenerator callGraphGenerator, final int i, final RandomGenerator randomGenerator) { final ArrayListMutableGraph g = callGraphGenerator.rcgs[i]; final StringBuilder sb = new StringBuilder(); sb.append("{\n"); sb.append("\t\"product\": \"graph-" + i + "\",\n"); sb.append("\t\"forge\": \"f\",\n"); sb.append("\t\"generator\": \"OPAL\",\n"); sb.append("\t\"version\": \"1.0\",\n"); sb.append("\t\"timestamp\": \"0\",\n"); sb.append("\t\"depset\": [\n\t\t"); // All generated DNFs are singletons for(final IntIterator d = callGraphGenerator.deps[i].iterator(); d.hasNext(); ) { sb.append( "[{ \"forge\": \"f\", \"product\": \"graph-" + d.nextInt() + "\", \"constraints\": [\"[1.0]\"] }]"); if (d.hasNext()) sb.append(", "); } sb.append("\n\t],\n"); sb.append("\t\"cha\": {\n"); for (int jj = 0; jj < g.numNodes() / 3; jj++) { sb.append("\t\t\"/p" + i + "/A" + jj + "\": {\n"); sb.append("\t\t\t\"methods\": {\n"); for (int j = 3 * jj; j < 3 * jj + 3 && j < g.numNodes(); j++) { sb.append("\t\t\t\t\"" + j + "\": \"/p" + i + "/A" + jj + ".f" + j + "()v\""); if (j < 3 * jj + 2 && j < g.numNodes() + 1) sb.append(","); sb.append("\n"); } sb.append("\t\t\t},\n"); sb.append("\t\t\t\"superInterfaces\": [],\n"); sb.append("\t\t\t\"sourceFile\": \"A" + jj + ".java\",\n"); sb.append("\t\t\t\"superClasses\": [\"/java.lang/Object\"]\n"); sb.append("\t\t}"); if (jj < g.numNodes() / 3 - 1) sb.append(","); sb.append("\n"); } sb.append("\t},\n"); sb.append("\t\"graph\": {\n"); // Internal calls sb.append("\t\t\"internalCalls\": [\n"); final ObjectArrayList<String> lines = new ObjectArrayList<>(); // Graph lines for(int j = 0; j < g.numNodes(); j++) { for(final IntIterator s = g.successors(j); s.hasNext();) lines.add("\t\t\t[\n\t\t\t\t" + callGraphGenerator.nodePermutation[i][j] + ",\n\t\t\t\t" + callGraphGenerator.nodePermutation[i][s.nextInt()] + "\n\t\t\t]"); } Collections.shuffle(lines, new Random(randomGenerator.nextLong())); // Permute graph lines for (int j = 0; j < lines.size(); j++) { sb.append(lines.get(j)); if (j < lines.size() - 1) sb.append(","); sb.append("\n"); } sb.append("\t\t],\n"); // External calls sb.append("\t\t\"externalCalls\": [\n"); lines.clear(); for(final int[] t: callGraphGenerator.source2Targets[i]) { lines.add("\t\t\t[\n\t\t\t\t\"" + callGraphGenerator.nodePermutation[i][t[0]] + "\",\n\t\t\t\t\"/p" + t[1] + "/A"+ callGraphGenerator.nodePermutation[t[1]][t[2]] / 3 + ".f" + callGraphGenerator.nodePermutation[t[1]][t[2]] +"()v\",\n" + "\t\t\t\t{\"invokevirtual\": \"1\"}\n" + "\t\t\t]"); } Collections.shuffle(lines, new Random(randomGenerator.nextLong())); // Permute graph lines for (int j = 0; j < lines.size(); j++) { sb.append(lines.get(j)); if (j < lines.size() - 1) sb.append(","); sb.append("\n"); } sb.append("\t\t]\n"); sb.append("\t}\n"); sb.append("}"); return sb.toString(); }
Example 10
Source File: AnnotatedPhrase.java From minie with GNU General Public License v3.0 | 4 votes |
/** * Detect the quantities in a phrase (given the sentence semantic graph). * @param sentSemGraph: the sentence semantic graph */ public void detectQuantities(SemanticGraph sentSemGraph, int i){ // Quantity words and edges ObjectArrayList<IndexedWord> qWords; ObjectArrayList<SemanticGraphEdge> qEdges = new ObjectArrayList<>(); // Tokens regex patterns String tokenRegexPattern; if (i == 1) tokenRegexPattern = REGEX.QUANTITY_SEQUENCE; else tokenRegexPattern = REGEX.QUANTITY_SEQUENCE_WITH_NO; TokenSequencePattern tPattern = TokenSequencePattern.compile(tokenRegexPattern); TokenSequenceMatcher tMatcher = tPattern.getMatcher(this.getWordCoreLabelList()); // Some reusable variables List<CoreMap> matchCoreMaps; ObjectOpenHashSet<IndexedWord> wordsSet = new ObjectOpenHashSet<>(); IndexedWord head; Set<SemanticGraphEdge> subtreeedges = new HashSet<>(); int matchCounter = -1; // Annotate the matches and their subtrees while (tMatcher.find()){ matchCounter++; matchCoreMaps = tMatcher.groupNodes(); // Get the head word of the phrase and see whether or not to add it to the quantities head = CoreNLPUtils.getRootFromCoreMapWordList(sentSemGraph, matchCoreMaps); if (head.ner().equals(NE_TYPE.DATE) || head.ner().equals(NE_TYPE.LOCATION) || head.ner().equals(NE_TYPE.MISC) || head.ner().equals(NE_TYPE.ORGANIZATION) || head.ner().equals(NE_TYPE.PERSON) || head.ner().equals(NE_TYPE.TIME)) continue; // Add the sutree elements of the head word if the right relations are in force for (IndexedWord w: sentSemGraph.getChildren(head)){ if ((sentSemGraph.reln(head, w) == EnglishGrammaticalRelations.QUANTIFIER_MODIFIER) || (sentSemGraph.reln(head, w) == EnglishGrammaticalRelations.ADVERBIAL_MODIFIER)){ wordsSet.add(w); subtreeedges = CoreNLPUtils.getSubTreeEdges(w, sentSemGraph, null); } } // Add the quantity words found and annotate them within the phrase wordsSet.addAll(CoreNLPUtils.getWordSetFromCoreMapList(matchCoreMaps)); wordsSet.addAll(CoreNLPUtils.getSortedWordsFromListOfEdges(subtreeedges)); wordsSet.retainAll(this.getWordList()); qWords = CoreNLPUtils.getSortedWordsFromSetOfWords(wordsSet); if (qWords.isEmpty()) continue; this.setQuantitiesFromWordList(qWords.clone(), qEdges, sentSemGraph, i, matchCounter); // Reset qWords.clear(); wordsSet.clear(); } }
Example 11
Source File: AnnotatedPhrase.java From minie with GNU General Public License v3.0 | 4 votes |
/** * When there are already annotated quantities, merge the ones which are right next to each other in a sequence. */ public void mergeAdjacentQuantities(){ // Reusable variables ObjectArrayList<IndexedWord> mergedQuantityWords = new ObjectArrayList<>(); ObjectArrayList<SemanticGraphEdge> mergedEdges = new ObjectArrayList<>(); ObjectArrayList<String> qIds = new ObjectArrayList<>(); ObjectOpenHashSet<IndexedWord> remWords = new ObjectOpenHashSet<>(); ObjectArrayList<IndexedWord> matches; // Token regex pattern and matcher TokenSequencePattern tPattern = TokenSequencePattern.compile(REGEX.ADJACENT_QUANTITIES); TokenSequenceMatcher tMatcher = tPattern.getMatcher(this.getWordCoreLabelList()); // Merge the quantities when matched while (tMatcher.find()){ // Get the merged words and edges from the quantities that should be merged. matches = CoreNLPUtils.getWordListFromCoreMapList(tMatcher.groupNodes()); for (int i = 0; i < matches.size(); i++){ // If it has preposition bridging two quantities, add it to the mergedQuantityWords list if (matches.get(i).tag().equals(POS_TAG.IN)) { mergedQuantityWords.add(matches.get(1)); remWords.add(matches.get(1)); } // Merge the adjacent quantities for (Quantity q: this.getQuantities()){ if ((Quantity.ST_QUANT + CHARACTER.UNDERSCORE + q.getId()).equals(matches.get(i).word())){ qIds.add(q.getId()); mergedQuantityWords.addAll(q.getQuantityWords()); mergedEdges.addAll(q.getQuantityEdges()); } } } // Add all the words and edges from the merged quantities to the first one and remove the rest for (int i = 0; i < this.getWordList().size(); i++){ if (this.getWordList().get(i).word().equals(Quantity.ST_QUANT + CHARACTER.UNDERSCORE + qIds.get(0))){ if (this.getQuantityByID(qIds.get(0)) != null){ this.getQuantityByID(qIds.get(0)).setWords(mergedQuantityWords); this.getQuantityByID(qIds.get(0)).setEdges(mergedEdges); for (int j = 1; j < qIds.size(); j++){ this.removeQuantityByID(qIds.get(j)); for (int k = i; k < this.getWordList().size(); k++){ if (this.getWordList().get(k).word().equals(Quantity.ST_QUANT + CHARACTER.UNDERSCORE + qIds.get(j))){ remWords.add(this.getWordList().get(k)); continue; } } } break; } } } // Remove and clear this.removeWordsFromList(remWords); remWords.clear(); qIds.clear(); } }
Example 12
Source File: ImplicitExtractions.java From minie with GNU General Public License v3.0 | 4 votes |
/** If ORG+ POS? NP PERSON+ => "PERSON" "is NP of" "ORG" (if there are , and or -> make multiple extractions) **/ public void extractPersonIsNPOfOrg() { // Reusable variables ObjectArrayList<AnnotatedPhrase> tempProp = new ObjectArrayList<>(); ObjectArrayList<AnnotatedPhrase> subjects = new ObjectArrayList<>(); IndexedWord subjRoot; IndexedWord objRoot; this.tPattern = TokenSequencePattern.compile(REGEX.T_ORG_NP_PERSON); this.tMatcher = this.tPattern.getMatcher(CoreNLPUtils.getCoreLabelListFromIndexedWordList(this.sentence)); while (this.tMatcher.find()){ // Set the relation to be "is-a" relation this.setIsARelation(); for (IndexedWord w: CoreNLPUtils.listOfCoreMapWordsToIndexedWordList(this.tMatcher.groupNodes())) { if (w.ner().equals(NE_TYPE.PERSON)) this.subj.addWordToList(w); else if (w.ner().equals(NE_TYPE.ORGANIZATION)) this.obj.addWordToList(w); else if (w.tag().equals(POS_TAG.POS)) continue; else if (w.lemma().equals(CHARACTER.COMMA) || w.lemma().equals("and") || w.lemma().equals("or")) { subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList()); subjects.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot)); this.subj.clear(); } else this.rel.addWordToList(w); } subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList()); subjects.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot)); objRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.obj.getWordList()); IndexedWord ofWord = new IndexedWord(); ofWord.setWord("of"); ofWord.setOriginalText("of"); ofWord.setTag(POS_TAG.IN); ofWord.setNER(NE_TYPE.NO_NER); ofWord.setLemma("of"); ofWord.setValue("of"); ofWord.setIndex(-2); this.rel.addWordToList(ofWord); for (AnnotatedPhrase subject: subjects) { // Add the subj/rel/obj to the temporary proposition and then to the real propositions subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, subject.getWordList()); tempProp.add(new AnnotatedPhrase(subject.getWordList(), subjRoot)); tempProp.add(new AnnotatedPhrase(this.rel.getWordList().clone(), this.rel.getRoot())); tempProp.add(new AnnotatedPhrase(this.obj.getWordList().clone(), objRoot)); this.propositions.add(new AnnotatedProposition(tempProp.clone(), new Attribution())); tempProp.clear(); } // Clean the variables this.subj.clear(); this.obj.clear(); this.rel.clear(); } }
Example 13
Source File: ImplicitExtractions.java From minie with GNU General Public License v3.0 | 4 votes |
/** If (NP+ PERSON) => "PERSON" "is" "NP" **/ public void extractNounPerson() { // Reusable variables ObjectArrayList<AnnotatedPhrase> tempProp = new ObjectArrayList<>(); IndexedWord subjRoot; IndexedWord objRoot; // Set the relation to be "is-a" relation this.setIsARelation(); this.tPattern = TokenSequencePattern.compile(REGEX.T_NP_PERSON); this.tMatcher = this.tPattern.getMatcher(CoreNLPUtils.getCoreLabelListFromIndexedWordList(this.sentence)); while (this.tMatcher.find()){ for (IndexedWord w: CoreNLPUtils.listOfCoreMapWordsToIndexedWordList(this.tMatcher.groupNodes())) { if (w.ner().equals(NE_TYPE.PERSON)) { this.subj.addWordToList(w); } else { if (w.lemma().toLowerCase().equals("mrs.") || w.lemma().toLowerCase().equals("ms.") || w.lemma().toLowerCase().equals("mrs") || w.lemma().toLowerCase().equals("ms")) { IndexedWord female = new IndexedWord(); female.setWord("female"); female.setOriginalText("female"); female.setTag(POS_TAG.NN); female.setNER(NE_TYPE.NO_NER); female.setLemma("female"); female.setValue("female"); female.setIndex(-2); this.obj.addWordToList(female); } else if (w.lemma().toLowerCase().equals("mr.") || w.lemma().toLowerCase().equals("mr")) { IndexedWord male = new IndexedWord(); male.setWord("male"); male.setOriginalText("male"); male.setTag(POS_TAG.NN); male.setNER(NE_TYPE.NO_NER); male.setLemma("male"); male.setValue("male"); male.setIndex(-2); this.obj.addWordToList(male); } else if (Polarity.NEG_WORDS.contains(w.lemma().toLowerCase())) { continue; } else { this.obj.addWordToList(w); } } } // Add the subj/rel/obj to the temporary proposition and then to the real propositions subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList()); objRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.obj.getWordList()); tempProp.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot)); tempProp.add(new AnnotatedPhrase(this.rel.getWordList().clone(), this.rel.getRoot())); tempProp.add(new AnnotatedPhrase(this.obj.getWordList().clone(), objRoot)); this.propositions.add(new AnnotatedProposition(tempProp.clone(), new Attribution())); // Clean the variables tempProp.clear(); this.subj.clear(); this.obj.clear(); } // Clear the relation this.rel.clear(); }
Example 14
Source File: ImplicitExtractions.java From minie with GNU General Public License v3.0 | 4 votes |
/** Hearst pattern 2_2: such NP_1 as NP_1, NP_2, ... [and|or] NP_n => "NP_2" "is" "NP_1", ... "NP_n", "is", "NP_1" **/ public void extractHearst2_2() { // Reusable variables IndexedWord tempWord; IndexedWord subjRoot; IndexedWord objRoot; ObjectArrayList<AnnotatedPhrase> tempProp = new ObjectArrayList<>(); // Set the relation to be "is-a" relation this.setIsARelation(); this.tPattern = TokenSequencePattern.compile(REGEX.T_HEARST_2_2); this.tMatcher = this.tPattern.getMatcher(CoreNLPUtils.getCoreLabelListFromIndexedWordList(this.sentence)); while (this.tMatcher.find()){ ObjectArrayList<IndexedWord> mWords = CoreNLPUtils.listOfCoreMapWordsToIndexedWordList(this.tMatcher.groupNodes()); int objInd = -1; // Define the object for (int i = 1; i < mWords.size(); i++) { if (!mWords.get(i).lemma().equals("as")) { tempWord = mWords.get(i); tempWord.setWord(mWords.get(i).lemma()); this.obj.addWordToList(tempWord); objInd = i + 2; } else break; } // Define subject(s) and add them to the proposition list for (int i = objInd; i < mWords.size(); i++) { tempWord = mWords.get(i); if ((tempWord.lemma().equals(CHARACTER.COMMA) || tempWord.lemma().equals("and") || tempWord.lemma().equals("or")) && tempWord.ner().equals(NE_TYPE.NO_NER)){ // Add the subj/rel/obj to the temporary proposition and then to the real propositions subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList()); objRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.obj.getWordList()); tempProp.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot)); tempProp.add(new AnnotatedPhrase(this.rel.getWordList().clone(), this.rel.getRoot())); tempProp.add(new AnnotatedPhrase(this.obj.getWordList().clone(), objRoot)); this.propositions.add(new AnnotatedProposition(tempProp.clone(), new Attribution())); // Clean the variables tempProp.clear(); this.subj.clear(); } else { this.subj.addWordToList(tempWord); } } // Add the subj/rel/obj to the temporary proposition and then to the real propositions subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList()); objRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.obj.getWordList()); tempProp.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot)); tempProp.add(new AnnotatedPhrase(this.rel.getWordList().clone(), this.rel.getRoot())); tempProp.add(new AnnotatedPhrase(this.obj.getWordList().clone(), objRoot)); this.propositions.add(new AnnotatedProposition(tempProp.clone(), new Attribution())); // Clean the variables tempProp.clear(); this.subj.clear(); this.obj.clear(); } // Clear the relation this.rel.clear(); }
Example 15
Source File: ImplicitExtractions.java From minie with GNU General Public License v3.0 | 4 votes |
/** NP , including (NP ,)* [or|and] NP **/ public void extractHearst4() { // Reusable variables IndexedWord tempWord; IndexedWord subjRoot; IndexedWord objRoot; ObjectArrayList<AnnotatedPhrase> tempProp = new ObjectArrayList<>(); // Set the relation to be "is-a" relation this.setIsARelation(); this.tPattern = TokenSequencePattern.compile(REGEX.T_HEARST_4); this.tMatcher = this.tPattern.getMatcher(CoreNLPUtils.getCoreLabelListFromIndexedWordList(this.sentence)); while (this.tMatcher.find()){ ObjectArrayList<IndexedWord> mWords = CoreNLPUtils.listOfCoreMapWordsToIndexedWordList(this.tMatcher.groupNodes()); // Detect object int objInd = -1; for (int i = 0; i < mWords.size(); i++) { if (mWords.get(i).lemma().equals(CHARACTER.COMMA) || mWords.get(i).word().equals("including") || mWords.get(i).word().equals("especially")){ objInd = i + 2; break; } this.obj.addWordToList(mWords.get(i)); } // Create subject(s) and add to propositions for (int i = objInd; i < mWords.size(); i++) { tempWord = mWords.get(i); if ((tempWord.lemma().equals(CHARACTER.COMMA) || tempWord.lemma().equals("and") || tempWord.lemma().equals("or")) && tempWord.ner().equals(NE_TYPE.NO_NER)) { // Add the subj/rel/obj to the temporary proposition and then to the real propositions subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList()); objRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.obj.getWordList()); tempProp.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot)); tempProp.add(new AnnotatedPhrase(this.rel.getWordList().clone(), this.rel.getRoot())); tempProp.add(new AnnotatedPhrase(this.obj.getWordList().clone(), objRoot)); this.propositions.add(new AnnotatedProposition(tempProp.clone(), new Attribution())); // Clean the variables tempProp.clear(); this.subj.clear(); } else { this.subj.addWordToList(tempWord); } } // Add the subj/rel/obj to the temporary proposition and then to the real propositions subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList()); objRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.obj.getWordList()); tempProp.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot)); tempProp.add(new AnnotatedPhrase(this.rel.getWordList().clone(), this.rel.getRoot())); tempProp.add(new AnnotatedPhrase(this.obj.getWordList().clone(), objRoot)); this.propositions.add(new AnnotatedProposition(tempProp.clone(), new Attribution())); // Clean the variables tempProp.clear(); this.subj.clear(); this.obj.clear(); } // Clear the relation this.rel.clear(); }