Java Code Examples for edu.stanford.nlp.util.Pair#makePair()
The following examples show how to use
edu.stanford.nlp.util.Pair#makePair() .
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: IntelKBPSemgrexExtractor.java From InformationExtraction with GNU General Public License v3.0 | 6 votes |
@Override public Pair<String, Double> classify(KBPInput input) { for (RelationType rel : RelationType.values()) { if (rules.containsKey(rel) && rel.entityType == input.subjectType && rel.validNamedEntityLabels.contains(input.objectType)) { Collection<SemgrexPattern> rulesForRel = rules.get(rel); CoreMap sentence = input.sentence.asCoreMap(Sentence::nerTags, Sentence::dependencyGraph); boolean matches = matches(sentence, rulesForRel, input, sentence.get(SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation.class)) || matches(sentence, rulesForRel, input, sentence.get(SemanticGraphCoreAnnotations.AlternativeDependenciesAnnotation.class)); if (matches) { //logger.log("MATCH for " + rel + ". " + sentence: + sentence + " with rules for " + rel); return Pair.makePair(rel.canonicalName, 1.0); } } } return Pair.makePair(NO_RELATION, 1.0); }
Example 2
Source File: KBPSemgrexExtractor.java From InformationExtraction with GNU General Public License v3.0 | 6 votes |
@Override public Pair<String, Double> classify(KBPInput input) { for (RelationType rel : RelationType.values()) { if (rules.containsKey(rel) && rel.entityType == input.subjectType && rel.validNamedEntityLabels.contains(input.objectType)) { Collection<SemgrexPattern> rulesForRel = rules.get(rel); CoreMap sentence = input.sentence.asCoreMap(Sentence::nerTags, Sentence::dependencyGraph); boolean matches = matches(sentence, rulesForRel, input, sentence.get(SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation.class)) || matches(sentence, rulesForRel, input, sentence.get(SemanticGraphCoreAnnotations.AlternativeDependenciesAnnotation.class)); if (matches) { //logger.log("MATCH for " + rel + ". " + sentence: + sentence + " with rules for " + rel); return Pair.makePair(rel.canonicalName, 1.0); } } } return Pair.makePair(NO_RELATION, 1.0); }
Example 3
Source File: IntelKBPEnsembleExtractor.java From InformationExtraction with GNU General Public License v3.0 | 5 votes |
private Pair<String, Double> classifyWithHighPrecision(KBPInput input) { Pair<String, Double> prediction = Pair.makePair(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION, 1.0); for (IntelKBPRelationExtractor extractor : extractors) { if (!extractor.getClass().equals(IntelKBPTokensregexExtractor.class)) continue; return extractor.classify(input); } return prediction; }
Example 4
Source File: IntelKBPEnsembleExtractor.java From InformationExtraction with GNU General Public License v3.0 | 5 votes |
private Pair<String, Double> classifyWithHighRecall(KBPInput input) { Pair<String, Double> prediction = Pair.makePair(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION, 1.0); for (IntelKBPRelationExtractor extractor : extractors) { Pair<String, Double> classifierPrediction = extractor.classify(input); logger.info(extractor.getClass().getSimpleName() + ": " + classifierPrediction + " for " + input.getObjectText() + " - " + input.getSubjectText()); if (!classifierPrediction.first.equals(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION)) { if (prediction.first.equals(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION)) prediction = classifierPrediction; else { prediction = classifierPrediction.second > prediction.second ? classifierPrediction : prediction; } } } return prediction; }
Example 5
Source File: IntelKBPEnsembleExtractor.java From InformationExtraction with GNU General Public License v3.0 | 5 votes |
private Pair<String, Double> classifyWithVote(KBPInput input) { HashMap<String, Double> relation2Weights = new HashMap<>(); Pair<String, Double> prediction = Pair.makePair(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION, 0.0); for (IntelKBPRelationExtractor extractor : extractors) { Pair<String, Double> classifierPrediction = extractor.classify(input); logger.info(extractor.getClass().getSimpleName() + ": " + classifierPrediction + " for " + input.getObjectText() + " - " + input.getSubjectText()); Double weight = relation2Weights.get(classifierPrediction.first); Double newWeight = weight == null ? 1.0 / extractors.length : weight + 1.0 / extractors.length; relation2Weights.put(classifierPrediction.first, newWeight); if (newWeight > prediction.second) prediction = Pair.makePair(classifierPrediction.first, newWeight); } return prediction; }
Example 6
Source File: IntelKBPEnsembleExtractor.java From InformationExtraction with GNU General Public License v3.0 | 5 votes |
private Pair<String, Double> classifyWithWeightedVote(KBPInput input) { HashMap<String, Double> relation2Weights = new HashMap<>(); Pair<String, Double> prediction = Pair.makePair(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION, 0.0); for (IntelKBPRelationExtractor extractor : extractors) { Pair<String, Double> classifierPrediction = extractor.classify(input); logger.info(extractor.getClass().getSimpleName() + ": " + classifierPrediction + " for " + input.getObjectText() + " - " + input.getSubjectText()); // if (classifierPrediction.first.equals(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION)) continue; Double weight = relation2Weights.get(classifierPrediction.first); Double newWeight = weight == null ? ModelWeight.getWeight(extractor) : weight + ModelWeight.getWeight(extractor); relation2Weights.put(classifierPrediction.first, newWeight); if (newWeight > prediction.second) prediction = Pair.makePair(classifierPrediction.first, newWeight); } return prediction; }
Example 7
Source File: IntelKBPEnsembleExtractor.java From InformationExtraction with GNU General Public License v3.0 | 5 votes |
private Pair<String, Double> classifyWithHighestScore(KBPInput input) { Pair<String, Double> prediction = Pair.makePair(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION, 1.0); for (IntelKBPRelationExtractor extractor : extractors) { Pair<String, Double> classifierPrediction = extractor.classify(input); logger.info(extractor.getClass().getSimpleName() + ": " + classifierPrediction + " for " + input.getObjectText() + " - " + input.getSubjectText()); if (prediction.first.equals(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION) || (!classifierPrediction.first.equals(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION) && classifierPrediction.second > prediction.second) ) { // The last prediction was NO_RELATION, or this is not NO_RELATION and has a higher score prediction = classifierPrediction; } } return prediction; }
Example 8
Source File: IntelKBPEnsembleExtractor.java From InformationExtraction with GNU General Public License v3.0 | 5 votes |
private Pair<String, Double> classifyDefault(KBPInput input) { Pair<String, Double> prediction = Pair.makePair(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION, 1.0); for (IntelKBPRelationExtractor extractor : extractors) { Pair<String, Double> classifierPrediction = extractor.classify(input); if (prediction.first.equals(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION) || (!classifierPrediction.first.equals(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION) && classifierPrediction.second > prediction.second) ){ // The last prediction was NO_RELATION, or this is not NO_RELATION and has a higher score prediction = classifierPrediction; } } return prediction; }
Example 9
Source File: KBPEnsembleExtractor.java From InformationExtraction with GNU General Public License v3.0 | 5 votes |
@Override public Pair<String, Double> classify(KBPInput input) { Pair<String, Double> prediction = Pair.makePair(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION, 1.0); for (edu.stanford.nlp.ie.KBPRelationExtractor extractor : extractors) { Pair<String, Double> classifierPrediction = extractor.classify(input); if (prediction.first.equals(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION) || (!classifierPrediction.first.equals(edu.stanford.nlp.ie.KBPRelationExtractor.NO_RELATION) && classifierPrediction.second > prediction.second) ){ // The last prediction was NO_RELATION, or this is not NO_RELATION and has a higher score prediction = classifierPrediction; } } return prediction; }
Example 10
Source File: StopwordAnnotator.java From coreNlp with Apache License 2.0 | 5 votes |
@Override public void annotate(Annotation annotation) { if (stopwords != null && stopwords.size() > 0 && annotation.containsKey(TokensAnnotation.class)) { List<CoreLabel> tokens = annotation.get(TokensAnnotation.class); for (CoreLabel token : tokens) { boolean isWordStopword = stopwords.contains(token.word().toLowerCase()); boolean isLemmaStopword = checkLemma ? stopwords.contains(token.word().toLowerCase()) : false; Pair<Boolean, Boolean> pair = Pair.makePair(isWordStopword, isLemmaStopword); token.set(StopwordAnnotator.class, pair); } } }