Java Code Examples for it.unimi.dsi.fastutil.objects.ObjectArrayList#get()
The following examples show how to use
it.unimi.dsi.fastutil.objects.ObjectArrayList#get() .
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: OptimizedExplosion.java From fabric-carpet with MIT License | 6 votes |
private static void method_24023(ObjectArrayList<Pair<ItemStack, BlockPos>> objectArrayList, ItemStack itemStack, BlockPos blockPos) { int i = objectArrayList.size(); for(int j = 0; j < i; ++j) { Pair<ItemStack, BlockPos> pair = (Pair)objectArrayList.get(j); ItemStack itemStack2 = pair.getLeft(); if (ItemEntity.canMerge(itemStack2, itemStack)) { ItemStack itemStack3 = ItemEntity.merge(itemStack2, itemStack, 16); objectArrayList.set(j, Pair.of(itemStack3, pair.getRight())); if (itemStack.isEmpty()) { return; } } } objectArrayList.add(Pair.of(itemStack, blockPos)); }
Example 2
Source File: FixMultiplicationsAndDivisions.java From WarpPI with Apache License 2.0 | 6 votes |
@Override public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction, final ObjectArrayList<Function> functionsList) throws Error { if (currentFunction instanceof Multiplication || currentFunction instanceof Division) { if (currentFunction.getParameter(0) == null && currentFunction.getParameter(1) == null) { if (curIndex.i - 1 >= 0 && curIndex.i + 1 < functionsList.size()) { final Function next = functionsList.get(curIndex.i + 1); final Function prev = functionsList.get(curIndex.i - 1); functionsList.set(curIndex.i, currentFunction.setParameter(0, prev).setParameter(1, next)); functionsList.remove(curIndex.i + 1); functionsList.remove(curIndex.i - 1); curIndex.i--; return true; } else if (currentFunction.getParameter(0) == null || currentFunction.getParameter(1) == null) { throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); } } } return false; }
Example 3
Source File: FixSumsAndSubtractions.java From WarpPI with Apache License 2.0 | 6 votes |
@Override public boolean eval(final IntWrapper curIndex, final Function lastFunction, final Function currentFunction, final ObjectArrayList<Function> functionsList) throws Error { if (currentFunction instanceof Sum || currentFunction instanceof Subtraction || currentFunction instanceof SumSubtraction) { if (currentFunction.getParameter(0) == null && currentFunction.getParameter(1) == null) { if (curIndex.i - 1 >= 0 && curIndex.i + 1 < functionsList.size()) { final Function next = functionsList.get(curIndex.i + 1); final Function prev = functionsList.get(curIndex.i - 1); functionsList.set(curIndex.i, currentFunction.setParameter(0, prev).setParameter(1, next)); functionsList.remove(curIndex.i + 1); functionsList.remove(curIndex.i - 1); curIndex.i--; return true; } else if (currentFunction.getParameter(0) == null || currentFunction.getParameter(1) == null) { throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); } } } return false; }
Example 4
Source File: PagesIndex.java From presto with Apache License 2.0 | 6 votes |
public void compact() { if (eagerCompact) { return; } for (int channel = 0; channel < types.size(); channel++) { ObjectArrayList<Block> blocks = channels[channel]; for (int i = nextBlockToCompact; i < blocks.size(); i++) { Block block = blocks.get(i); // Copy the block to compact its size Block compactedBlock = block.copyRegion(0, block.getPositionCount()); blocks.set(i, compactedBlock); pagesMemorySize -= block.getRetainedSizeInBytes(); pagesMemorySize += compactedBlock.getRetainedSizeInBytes(); } } nextBlockToCompact = channels[0].size(); estimatedSize = calculateEstimatedSize(); }
Example 5
Source File: UCCTreeElement.java From metanome-algorithms with Apache License 2.0 | 5 votes |
public int addUniqueColumnCombinationsInto(UniqueColumnCombinationResultReceiver resultReceiver, BitSet ucc, ObjectArrayList<ColumnIdentifier> columnIdentifiers, List<PositionListIndex> plis) throws CouldNotReceiveResultException, ColumnNameMismatchException { int numUCCs = 0; if (this.isUCC) { ColumnIdentifier[] columns = new ColumnIdentifier[ucc.cardinality()]; int j = 0; for (int i = ucc.nextSetBit(0); i >= 0; i = ucc.nextSetBit(i + 1)) { int columnId = plis.get(i).getAttribute(); // Here we translate the column i back to the real column i before the sorting columns[j++] = columnIdentifiers.get(columnId); } UniqueColumnCombination uccResult = new UniqueColumnCombination(new ColumnCombination(columns)); resultReceiver.receiveResult(uccResult); numUCCs++; return numUCCs; } if (this.getChildren() == null) return numUCCs; for (int childAttr = 0; childAttr < this.numAttributes; childAttr++) { UCCTreeElement element = this.getChildren()[childAttr]; if (element != null) { ucc.set(childAttr); numUCCs += element.addUniqueColumnCombinationsInto(resultReceiver, ucc, columnIdentifiers, plis); ucc.clear(childAttr); } } return numUCCs; }
Example 6
Source File: FDTreeElement.java From winter with Apache License 2.0 | 5 votes |
public void addFunctionalDependenciesInto(List<FunctionalDependency> functionalDependencies, OpenBitSet lhs, ObjectArrayList<ColumnIdentifier> columnIdentifiers, List<PositionListIndex> plis) { for (int rhs = this.rhsFds.nextSetBit(0); rhs >= 0; rhs = this.rhsFds.nextSetBit(rhs + 1)) { ColumnIdentifier[] columns = new ColumnIdentifier[(int) lhs.cardinality()]; int j = 0; for (int i = lhs.nextSetBit(0); i >= 0; i = lhs.nextSetBit(i + 1)) { int columnId = plis.get(i).getAttribute(); // Here we translate the column i back to the real column i before the sorting columns[j++] = columnIdentifiers.get(columnId); } ColumnCombination colCombination = new ColumnCombination(columns); int rhsId = plis.get(rhs).getAttribute(); // Here we translate the column rhs back to the real column rhs before the sorting FunctionalDependency fdResult = new FunctionalDependency(colCombination, columnIdentifiers.get(rhsId)); functionalDependencies.add(fdResult); } if (this.getChildren() == null) return; for (int childAttr = 0; childAttr < this.numAttributes; childAttr++) { FDTreeElement element = this.getChildren()[childAttr]; if (element != null) { lhs.set(childAttr); element.addFunctionalDependenciesInto(functionalDependencies, lhs, columnIdentifiers, plis); lhs.clear(childAttr); } } }
Example 7
Source File: CoreNLPUtils.java From minie with GNU General Public License v3.0 | 5 votes |
/** * Given a list of indexed words and a semantic graph, return the root word of the word list. We assume that * all the words from the list can be found in the semantic graph sg, and the words in wordList are connected * within the semantic graph of the sentence - sg. If there are multiple words which have the shortest distance * to the sentence root, then choose the most-left verb. * * @param sg: sentence semantic graph * @param wordsList: list of words from which to choose "root" from * @return */ public static IndexedWord getVerbRootFromWordList(SemanticGraph sg, ObjectArrayList<IndexedWord> wordList){ IndexedWord constituentRoot = null; IntArrayList shortestDirectedPathDistances = new IntArrayList(); int minPathToRoot = Integer.MAX_VALUE; int pathToRoot = -1; for (int i = 0; i < wordList.size(); i++){ // The words with index -2 are the ones that cannot be found in the semantic graph (synthetic words) // This happens in the relations (see in clausie.ClauseDetector.java), and those words are the head words if (wordList.get(i).index() == -2){ return wordList.get(i); } pathToRoot = sg.getShortestDirectedPathNodes(sg.getFirstRoot(), wordList.get(i)).size(); if (pathToRoot < minPathToRoot){ minPathToRoot = pathToRoot; } shortestDirectedPathDistances.add(pathToRoot); } // If the shortest path is one element, return it, else, return the first verb containing that index if (FastUtil.countElement(minPathToRoot, shortestDirectedPathDistances) == 1) return wordList.get(shortestDirectedPathDistances.indexOf(minPathToRoot)); else { for (int i = 0; i < shortestDirectedPathDistances.size(); i++){ if (shortestDirectedPathDistances.getInt(i) == minPathToRoot){ if (isVerb(wordList.get(i).tag())){ constituentRoot = wordList.get(i); break; } } } } return constituentRoot; }
Example 8
Source File: CoreNLPUtils.java From minie with GNU General Public License v3.0 | 5 votes |
/** * Given a list of indexed words and a semantic graph, return the root word of the word list. We assume that * all the words from the list can be found in the semantic graph sg, and the words in wordList are connected * within the semantic graph of the sentence - sg, and that they all share a common root. * @param sg: semantic graph of the sentence * @param wordList: the phrase from the sentence, represented as a list of words * @return the root word from the phrase */ public static IndexedWord getRootFromWordList(SemanticGraph sg, ObjectArrayList<IndexedWord> wordList){ // If the word list is consisted of one word - return that word if (wordList.size() == 1) return wordList.get(0); IndexedWord constituentRoot = null; // We only search as high as grandparents // constituentRoot = sg.getCommonAncestor(wordList.get(0), wordList.get(wordList.size()-1)); // If the commonancestor is deeper in the tree, the constituent root is the word with shortest distance // to the root of the sentence int minPathToRoot = Integer.MAX_VALUE; int pathToRoot = -1; for (int i = 0; i < wordList.size(); i++){ // The words with index -2 are the ones that cannot be found in the semantic graph (synthetic words) // This happens in the relations (see in clausie.ClauseDetector.java), and those words are the head words if (wordList.get(i).index() == -2){ return wordList.get(i); } pathToRoot = sg.getShortestDirectedPathNodes(sg.getFirstRoot(), wordList.get(i)).size(); if (pathToRoot < minPathToRoot){ //TODO: throws NPE sometimes minPathToRoot = pathToRoot; constituentRoot = wordList.get(i); } } return constituentRoot; }
Example 9
Source File: FDTreeElement.java From metanome-algorithms with Apache License 2.0 | 5 votes |
public void addFunctionalDependenciesInto(List<FunctionalDependency> functionalDependencies, BitSet lhs, ObjectArrayList<ColumnIdentifier> columnIdentifiers, List<PositionListIndex> plis) { for (int rhs = this.rhsFds.nextSetBit(0); rhs >= 0; rhs = this.rhsFds.nextSetBit(rhs + 1)) { ColumnIdentifier[] columns = new ColumnIdentifier[lhs.cardinality()]; int j = 0; for (int i = lhs.nextSetBit(0); i >= 0; i = lhs.nextSetBit(i + 1)) { int columnId = plis.get(i).getAttribute(); // Here we translate the column i back to the real column i before the sorting columns[j++] = columnIdentifiers.get(columnId); } ColumnCombination colCombination = new ColumnCombination(columns); int rhsId = plis.get(rhs).getAttribute(); // Here we translate the column rhs back to the real column rhs before the sorting FunctionalDependency fdResult = new FunctionalDependency(colCombination, columnIdentifiers.get(rhsId)); functionalDependencies.add(fdResult); } if (this.getChildren() == null) return; for (int childAttr = 0; childAttr < this.numAttributes; childAttr++) { FDTreeElement element = this.getChildren()[childAttr]; if (element != null) { lhs.set(childAttr); element.addFunctionalDependenciesInto(functionalDependencies, lhs, columnIdentifiers, plis); lhs.clear(childAttr); } } }
Example 10
Source File: FDTreeElement.java From metanome-algorithms with Apache License 2.0 | 5 votes |
public int addFunctionalDependenciesInto(FunctionalDependencyResultReceiver resultReceiver, BitSet lhs, ObjectArrayList<ColumnIdentifier> columnIdentifiers, List<PositionListIndex> plis) throws CouldNotReceiveResultException, ColumnNameMismatchException { int numFDs = 0; for (int rhs = this.rhsFds.nextSetBit(0); rhs >= 0; rhs = this.rhsFds.nextSetBit(rhs + 1)) { ColumnIdentifier[] columns = new ColumnIdentifier[lhs.cardinality()]; int j = 0; for (int i = lhs.nextSetBit(0); i >= 0; i = lhs.nextSetBit(i + 1)) { int columnId = plis.get(i).getAttribute(); // Here we translate the column i back to the real column i before the sorting columns[j++] = columnIdentifiers.get(columnId); } ColumnCombination colCombination = new ColumnCombination(columns); int rhsId = plis.get(rhs).getAttribute(); // Here we translate the column rhs back to the real column rhs before the sorting FunctionalDependency fdResult = new FunctionalDependency(colCombination, columnIdentifiers.get(rhsId)); resultReceiver.receiveResult(fdResult); numFDs++; } if (this.getChildren() == null) return numFDs; for (int childAttr = 0; childAttr < this.numAttributes; childAttr++) { FDTreeElement element = this.getChildren()[childAttr]; if (element != null) { lhs.set(childAttr); numFDs += element.addFunctionalDependenciesInto(resultReceiver, lhs, columnIdentifiers, plis); lhs.clear(childAttr); } } return numFDs; }
Example 11
Source File: FDTreeElement.java From metanome-algorithms with Apache License 2.0 | 5 votes |
public void addFunctionalDependenciesInto(List<FunctionalDependency> functionalDependencies, BitSet lhs, ObjectArrayList<ColumnIdentifier> columnIdentifiers, List<PositionListIndex> plis) { for (int rhs = this.rhsFds.nextSetBit(0); rhs >= 0; rhs = this.rhsFds.nextSetBit(rhs + 1)) { ColumnIdentifier[] columns = new ColumnIdentifier[lhs.cardinality()]; int j = 0; for (int i = lhs.nextSetBit(0); i >= 0; i = lhs.nextSetBit(i + 1)) { int columnId = plis.get(i).getAttribute(); // Here we translate the column i back to the real column i before the sorting columns[j++] = columnIdentifiers.get(columnId); } ColumnCombination colCombination = new ColumnCombination(columns); int rhsId = plis.get(rhs).getAttribute(); // Here we translate the column rhs back to the real column rhs before the sorting FunctionalDependency fdResult = new FunctionalDependency(colCombination, columnIdentifiers.get(rhsId)); functionalDependencies.add(fdResult); } if (this.getChildren() == null) return; for (int childAttr = 0; childAttr < this.numAttributes; childAttr++) { FDTreeElement element = this.getChildren()[childAttr]; if (element != null) { lhs.set(childAttr); element.addFunctionalDependenciesInto(functionalDependencies, lhs, columnIdentifiers, plis); lhs.clear(childAttr); } } }
Example 12
Source File: TaneAlgorithmFilterTreeDirect.java From metanome-algorithms with Apache License 2.0 | 5 votes |
/** * Get all combinations, which can be built out of the elements of a prefix block * * @param list * @return */ private ObjectArrayList<BitSet[]> getListCombinations(ObjectArrayList<BitSet> list) { ObjectArrayList<BitSet[]> combinations = new ObjectArrayList<BitSet[]>(); for (int a = 0; a < list.size(); a++) { for (int b = a + 1; b < list.size(); b++) { BitSet[] combi = new BitSet[2]; combi[0] = list.get(a); combi[1] = list.get(b); combinations.add(combi); } } return combinations; }
Example 13
Source File: DefaultPropositionGenerator.java From minie with GNU General Public License v3.0 | 5 votes |
/** * Given a proposition and a list of constituency types (corresponding the phrases of the proposition), * push the constituents to the relation if needed * @param proposition * @param constTypes */ private static void pushConstituentsToRelation(Proposition p, ObjectArrayList<Constituent.Type> types){ // Push constituents to the relation if the 4th constituent is an adverbial // (for SVA(A), SVC(A), SVO(A), SVOA) if (types.get(3) == Constituent.Type.ADVERBIAL){ // If the adverbial is consisted of one adverb, don't push the previous constituent if (p.getPhrases().get(3).getWordList().size() > 1) { // If CCOMP don't push it if (types.get(2) == Constituent.Type.CCOMP) { return; } pushConstituentToRelation(p, 2); } // If the adverbial is consisted of one adverb, push the adverb to the relation else if (p.getPhrases().get(3).getWordList().size() == 1){ if (CoreNLPUtils.isAdverb(p.getPhrases().get(3).getWordList().get(0).tag())) pushConstituentToRelation(p, 3); else pushConstituentToRelation(p, 2); } } // If the 3rd constituent is an indirect/direct object or an adverbial (for SVOO/SVOC, SVOA) else if (types.get(2) == Constituent.Type.IOBJ || types.get(2) == Constituent.Type.DOBJ || types.get(2) == Constituent.Type.ADVERBIAL){ pushConstituentToRelation(p, 2); } }
Example 14
Source File: TaneAlgorithm.java From metanome-algorithms with Apache License 2.0 | 5 votes |
/** * Get all combinations, which can be built out of the elements of a prefix block * * @param list: List of BitSets, which are in the same prefix block. * @return All combinations of the BitSets. */ private ObjectArrayList<BitSet[]> getListCombinations(ObjectArrayList<BitSet> list) { ObjectArrayList<BitSet[]> combinations = new ObjectArrayList<BitSet[]>(); for (int a = 0; a < list.size(); a++) { for (int b = a + 1; b < list.size(); b++) { BitSet[] combi = new BitSet[2]; combi[0] = list.get(a); combi[1] = list.get(b); combinations.add(combi); } } return combinations; }
Example 15
Source File: SumMethod1.java From WarpPI with Apache License 2.0 | 5 votes |
public static ObjectArrayList<Function> execute(final Function f) throws Error, InterruptedException { Function result; final MathContext root = f.getMathContext(); final ObjectArrayList<Function> elements = SumMethod1.getSumElements(f); final int[] workingElementCouple = SumMethod1.getFirstWorkingSumCouple(root, elements); final Function elem1 = elements.get(workingElementCouple[0]); final Function elem2 = elements.get(workingElementCouple[1]); final int size = elements.size(); Function prec = new Sum(root, elem1, elem2); for (int i = size - 1; i >= 0; i--) { if (i != workingElementCouple[0] & i != workingElementCouple[1]) { if (Thread.interrupted()) { throw new InterruptedException(); } final Function a = prec; final Function b = elements.get(i); if (b instanceof Negative) { prec = new Subtraction(root, a, ((Negative) b).getParameter()); ((FunctionOperator) prec).getParameter2(); } else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) { prec = new Subtraction(root, a, ((Number) b).multiply(new Number(root, -1))); ((FunctionOperator) prec).getParameter2(); } else { prec = new Sum(root, a, b); } } } result = prec; final ObjectArrayList<Function> results = new ObjectArrayList<>(); results.add(result); return results; }
Example 16
Source File: TaneAlgorithmFilterTreeEnd.java From metanome-algorithms with Apache License 2.0 | 4 votes |
@Override public void execute() throws AlgorithmExecutionException { level0 = new Object2ObjectOpenHashMap<BitSet, CombinationHelper>(); level1 = new Object2ObjectOpenHashMap<BitSet, CombinationHelper>(); prefix_blocks = new Object2ObjectOpenHashMap<BitSet, ObjectArrayList<BitSet>>(); // Get information about table from database ObjectArrayList<Object2ObjectOpenHashMap<Object, LongBigArrayBigList>> partitions = loadData(); setColumnIdentifiers(); numberAttributes = this.columnNames.size(); // Initialize table used for stripped partition product tTable = new LongBigArrayBigList(numberTuples); for (long i = 0; i < numberTuples; i++) { tTable.add(-1); } // Initialize FDTree to store fds and filter them before returning them. dependencies = new FDTree(numberAttributes); // Initialize Level 0 CombinationHelper chLevel0 = new CombinationHelper(); BitSet rhsCandidatesLevel0 = new BitSet(); rhsCandidatesLevel0.set(1, numberAttributes + 1); chLevel0.setRhsCandidates(rhsCandidatesLevel0); StrippedPartition spLevel0 = new StrippedPartition(numberTuples); chLevel0.setPartition(spLevel0); spLevel0 = null; level0.put(new BitSet(), chLevel0); chLevel0 = null; // Initialize Level 1 for (int i = 1; i <= numberAttributes; i++) { BitSet combinationLevel1 = new BitSet(); combinationLevel1.set(i); CombinationHelper chLevel1 = new CombinationHelper(); BitSet rhsCandidatesLevel1 = new BitSet(); rhsCandidatesLevel1.set(1, numberAttributes + 1); chLevel1.setRhsCandidates(rhsCandidatesLevel0); StrippedPartition spLevel1 = new StrippedPartition(partitions.get(i - 1)); chLevel1.setPartition(spLevel1); level1.put(combinationLevel1, chLevel1); } partitions = null; // while loop (main part of TANE) int l = 1; while (!level1.isEmpty() && l <= numberAttributes) { // compute dependencies for a level computeDependencies(l); // prune the search space prune(); // compute the combinations for the next level generateNextLevel(); l++; } dependencies.filterGeneralizations(); addAllDependenciesToResultReceiver(); }
Example 17
Source File: MinIE.java From minie with GNU General Public License v3.0 | 4 votes |
/** * Process possessives in the object. * If we have ("SUBJ", "REL", "NP_1 POS NP_2"), then: ("SUBJ", "REL + NP_1 + of", "NP_2") * @param prop: proposition (list of annotated phrases) */ public void processPoss(ObjectArrayList<AnnotatedPhrase> prop){ // If there's no object (clause type SV), return if (prop.size() < 3) return; AnnotatedPhrase object = prop.get(2); AnnotatedPhrase rel = prop.get(1); TokenSequencePattern tPattern = TokenSequencePattern.compile(REGEX.T_NP_POS_NP); TokenSequenceMatcher tMatcher = tPattern.getMatcher(object.getWordCoreLabelList()); int posIndex = -1; while (tMatcher.find()){ List<CoreMap> match = tMatcher.groupNodes(); // Check if the first/last word of the match is the first/last word of the object CoreLabel firstWord = new CoreLabel(match.get(0)); CoreLabel lastWord = new CoreLabel(match.get(match.size() - 1)); boolean check = false; if (firstWord.index() == object.getWordList().get(0).index()){ if (lastWord.index() == object.getWordList().get(object.getWordList().size() - 1).index()){ check = true; } } if (!check) break; for (CoreMap cm: match){ CoreLabel cl = new CoreLabel(cm); if (cl.tag().equals(POS_TAG.POS) && (cl.ner().equals(NE_TYPE.NO_NER))){ posIndex = object.getWordCoreLabelList().indexOf(cl); break; } } } if (posIndex > -1){ IndexedWord of = new IndexedWord(); of.setOriginalText("of"); of.setLemma("of"); of.setWord("of"); of.setTag("IN"); of.setNER("O"); of.setIndex(-1); ObjectArrayList<IndexedWord> pushedWords = new ObjectArrayList<>(); object.removeWordFromList(posIndex); for (int i = posIndex; i < object.getWordList().size(); i++){ pushedWords.add(object.getWordList().get(i)); } rel.addWordsToList(pushedWords); rel.addWordToList(of); object.removeWordsFromList(pushedWords); } }
Example 18
Source File: MinIE.java From minie with GNU General Public License v3.0 | 4 votes |
/** * Given a proposition, check if it should be pruned or not. * @param proposition * @return true, if the proposition should be pruned, false otherwise */ private boolean pruneAnnotatedProposition(ObjectArrayList<AnnotatedPhrase> proposition){ AnnotatedPhrase subj = proposition.get(0); AnnotatedPhrase rel = proposition.get(1); // If there is no verb in the relation, prune // TODO: check why this is happening! In some of these cases, the verb gets deleted for some reason. // This happens when CCs are being processed. Empty relations too if (!CoreNLPUtils.hasVerb(rel.getWordList())) return true; // Empty subject if (subj.getWordList().isEmpty()) return true; if (proposition.size() == 3){ AnnotatedPhrase obj = proposition.get(2); // Check if the object is empty (shouldn't happen, but just in case) if (obj.getWordList().isEmpty()) return true; // The last word of the object IndexedWord w = obj.getWordList().get(obj.getWordList().size()-1); // If the last word is preposition if (w.tag().equals(POS_TAG.IN) && w.ner().equals(NE_TYPE.NO_NER)) return true; // When the object is consisted of one preposition if (obj.getWordList().size() == 1){ // If the object is just one preposition - prune if (w.tag().equals(POS_TAG.IN) || w.tag().equals(POS_TAG.TO)){ return true; } } // When the object ends with one of the POS tags: WDT, WP$, WP or WRB if (w.tag().equals(POS_TAG.WDT) || w.tag().equals(POS_TAG.WP) || w.tag().equals(POS_TAG.WP_P) || w.tag().equals(POS_TAG.WRB)){ return true; } // Prune if clause modifier detected if (this.detectClauseModifier(proposition)){ return true; } // Prune if there are NERs on both sides of "be" relation // TODO: do this for implicit extractions only? if ((rel.getWordList().size() == 1)) { if (rel.getWordList().get(0).lemma().equals("be")) { if (subj.isOneNER() && obj.isOneNER()) { if (!obj.getWordList().get(0).ner().equals(NE_TYPE.MISC)) { return true; } } } } } return false; }
Example 19
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 20
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(); }