/** * Given the node arg string, converts it into an IndexedWord. */ public static IndexedWord fromCheapString(String rawArg) { String arg = rawArg.substring(1, rawArg.length()-1); String[] tuples=arg.split(ATOM_DELIMITER); Map<String,String> args = Generics.newHashMap(); for (String tuple : tuples) { String[] vals = tuple.split(TUPLE_DELIMITER); String key = vals[0]; String value = ""; if (vals.length == 2) value = vals[1]; args.put(key, value); } IndexedWord newWord = new IndexedWord(); newWord.setWord(args.get(WORD_KEY)); newWord.setLemma(args.get(LEMMA_KEY)); newWord.setTag(args.get(POS_KEY)); newWord.setValue(args.get(VALUE_KEY)); newWord.setOriginalText(args.get(CURRENT_KEY)); return newWord; }
/** * Given an iterable set of distinct vertices, creates a new mapping that maps the * original vertices to a set of "generic" versions. Used for generalizing tokens in discovered rules. * * @param verts Vertices to anonymize * @param prefix Prefix to assign to this anonymization */ public static Map<IndexedWord, IndexedWord> anonymyizeNodes(Iterable<IndexedWord> verts, String prefix) { Map<IndexedWord, IndexedWord> retMap = Generics.newHashMap(); int index = 1; for (IndexedWord orig: verts) { IndexedWord genericVert = new IndexedWord(orig); genericVert.set(CoreAnnotations.LemmaAnnotation.class, ""); String genericValue = prefix+index; genericVert.setValue(genericValue); genericVert.setWord(genericValue); genericVert.setOriginalText(genericValue); index++; retMap.put(orig, genericVert); } return retMap; }
private Pair<IndexedWord, GrammaticalRelation> getGovAndReln(double govPseudoIndex, IndexedWord word, String relationName, List<IndexedWord> sortedTokens) { IndexedWord gov; GrammaticalRelation reln; if (relationName.equals("root")) { reln = GrammaticalRelation.ROOT; } else { reln = GrammaticalRelation.valueOf(this.lang, relationName); } if (govPseudoIndex == 0.0) { gov = new IndexedWord(word.docID(), word.sentIndex(), 0); gov.setValue("ROOT"); } else { gov = this.getToken(sortedTokens, govPseudoIndex); } return Generics.newPair(gov, reln); }
/** Returns a list of TypedDependency in the graph. * This method goes through all SemanticGraphEdge and converts them * to TypedDependency. * * @return A List of TypedDependency in the graph */ public Collection<TypedDependency> typedDependencies() { Collection<TypedDependency> dependencies = new ArrayList<>(); IndexedWord root = null; for (IndexedWord node : roots) { if (root == null) { root = new IndexedWord(node.docID(), node.sentIndex(), 0); root.setValue("ROOT"); } TypedDependency dependency = new TypedDependency(ROOT, root, node); dependencies.add(dependency); } for (SemanticGraphEdge e : this.edgeIterable()){ TypedDependency dependency = new TypedDependency(e.getRelation(), e.getGovernor(), e.getDependent()); if (e.isExtra()) { dependency.setExtra(); } dependencies.add(dependency); } return dependencies; }
newNode.setValue(StringUtils.join(sortedSubgraphNodes.stream().map(IndexedWord::value), " ")); newNode.setWord(StringUtils.join(sortedSubgraphNodes.stream().map(IndexedWord::word), " ")); newNode.setLemma(StringUtils.join(sortedSubgraphNodes.stream().map(x -> x.lemma() == null ? x.word() : x.lemma()), " "));
public Label newLabel(String labelStr) { IndexedWord label = new IndexedWord(); label.setValue(labelStr); return label; }
public Label newLabel(String labelStr) { IndexedWord label = new IndexedWord(); label.setValue(labelStr); return label; }
/** * Given an iterable set of distinct vertices, creates a new mapping that maps the * original vertices to a set of "generic" versions. Used for generalizing tokens in discovered rules. * * @param verts Vertices to anonymize * @param prefix Prefix to assign to this anonymization */ public static Map<IndexedWord, IndexedWord> anonymyizeNodes(Iterable<IndexedWord> verts, String prefix) { Map<IndexedWord, IndexedWord> retMap = Generics.newHashMap(); int index = 1; for (IndexedWord orig: verts) { IndexedWord genericVert = new IndexedWord(orig); genericVert.set(CoreAnnotations.LemmaAnnotation.class, ""); String genericValue = prefix+index; genericVert.setValue(genericValue); genericVert.setWord(genericValue); genericVert.setOriginalText(genericValue); index++; retMap.put(orig, genericVert); } return retMap; }
/** * Given an iterable set of distinct vertices, creates a new mapping that maps the * original vertices to a set of "generic" versions. Used for generalizing tokens in discovered rules. * * @param verts Vertices to anonymize * @param prefix Prefix to assign to this anonymization */ public static Map<IndexedWord, IndexedWord> anonymyizeNodes(Iterable<IndexedWord> verts, String prefix) { Map<IndexedWord, IndexedWord> retMap = Generics.newHashMap(); int index = 1; for (IndexedWord orig: verts) { IndexedWord genericVert = new IndexedWord(orig); genericVert.set(CoreAnnotations.LemmaAnnotation.class, ""); String genericValue = prefix+index; genericVert.setValue(genericValue); genericVert.setWord(genericValue); genericVert.setOriginalText(genericValue); index++; retMap.put(orig, genericVert); } return retMap; }
private static Pair<IndexedWord, GrammaticalRelation> getGovAndReln(int govIdx, int copyCount, IndexedWord word, String relationName, List<IndexedWord> sortedTokens) { IndexedWord gov; GrammaticalRelation reln; if (relationName.equals("root")) { reln = GrammaticalRelation.ROOT; } else { reln = GrammaticalRelation.valueOf(Language.UniversalEnglish, relationName); } if (govIdx == 0) { gov = new IndexedWord(word.docID(), word.sentIndex(), 0); gov.setValue("ROOT"); } else { gov = SentenceProcessor.getToken(sortedTokens, govIdx, copyCount); } return Generics.newPair(gov, reln); }
private static Pair<IndexedWord, GrammaticalRelation> getGovAndReln(int govIdx, int copyCount, IndexedWord word, String relationName, List<IndexedWord> sortedTokens) { IndexedWord gov; GrammaticalRelation reln; if (relationName.equals("root")) { reln = GrammaticalRelation.ROOT; } else { reln = GrammaticalRelation.valueOf(Language.UniversalEnglish, relationName); } if (govIdx == 0) { gov = new IndexedWord(word.docID(), word.sentIndex(), 0); gov.setValue("ROOT"); } else { gov = SentenceProcessor.getToken(sortedTokens, govIdx, copyCount); } return Generics.newPair(gov, reln); }
word.setValue(bits[1]);
/** Returns a list of TypedDependency in the graph. * This method goes through all SemanticGraphEdge and converts them * to TypedDependency. * * @return A List of TypedDependency in the graph */ public Collection<TypedDependency> typedDependencies() { Collection<TypedDependency> dependencies = new ArrayList<>(); IndexedWord root = null; for (IndexedWord node : roots) { if (root == null) { root = new IndexedWord(node.docID(), node.sentIndex(), 0); root.setValue("ROOT"); } TypedDependency dependency = new TypedDependency(ROOT, root, node); dependencies.add(dependency); } for (SemanticGraphEdge e : this.edgeIterable()){ TypedDependency dependency = new TypedDependency(e.getRelation(), e.getGovernor(), e.getDependent()); if (e.isExtra()) { dependency.setExtra(); } dependencies.add(dependency); } return dependencies; }
/** Returns a list of TypedDependency in the graph. * This method goes through all SemanticGraphEdge and converts them * to TypedDependency. * * @return A List of TypedDependency in the graph */ public Collection<TypedDependency> typedDependencies() { Collection<TypedDependency> dependencies = new ArrayList<>(); IndexedWord root = null; for (IndexedWord node : roots) { if (root == null) { root = new IndexedWord(node.docID(), node.sentIndex(), 0); root.setValue("ROOT"); } TypedDependency dependency = new TypedDependency(ROOT, root, node); dependencies.add(dependency); } for (SemanticGraphEdge e : this.edgeIterable()){ TypedDependency dependency = new TypedDependency(e.getRelation(), e.getGovernor(), e.getDependent()); if (e.isExtra()) { dependency.setExtra(); } dependencies.add(dependency); } return dependencies; }
/** Returns a list of TypedDependency in the graph. * This method goes through all SemanticGraphEdge and converts them * to TypedDependency. * * @return A List of TypedDependency in the graph */ public Collection<TypedDependency> typedDependencies() { Collection<TypedDependency> dependencies = new ArrayList<TypedDependency>(); // FIXME: parts of the code (such as the dependencies) expect the // TreeGraphNodes to be == equal, but that doesn't apply the way // this method is written TreeGraphNode root = null; for (IndexedWord node : roots) { if (root == null) { IndexedWord rootLabel = new IndexedWord(node.docID(), node.sentIndex(), 0); rootLabel.setValue("ROOT"); root = new TreeGraphNode(rootLabel); } TypedDependency dependency = new TypedDependency(ROOT, root, new TreeGraphNode(node)); dependencies.add(dependency); } for (SemanticGraphEdge e : this.edgeIterable()){ TreeGraphNode gov = new TreeGraphNode(e.getGovernor()); TreeGraphNode dep = new TreeGraphNode(e.getDependent()); TypedDependency dependency = new TypedDependency(e.getRelation(), gov, dep); dependencies.add(dependency); } return dependencies; }