public class BasicRelationExtractor extends java.lang.Object implements Extractor
Modifier and Type | Field and Description |
---|---|
protected LinearClassifier<java.lang.String,java.lang.String> |
classifier |
protected boolean |
createUnrelatedRelations
If true, it creates automatically negative examples by generating all combinations between EntityMentions in a sentence
This is the common behavior, but for some domain (i.e., KBP) it must disabled.
|
int |
featureCountThreshold |
RelationFeatureFactory |
featureFactory |
java.lang.String |
relationExtractorClassifierType
which classifier to use (can be 'linear' or 'svm')
|
protected RelationMentionFactory |
relationMentionFactory |
double |
sigma
strength of the prior on the linear classifier (passed to LinearClassifierFactory) or the C constant if relationExtractorClassifierType=svm
|
Constructor and Description |
---|
BasicRelationExtractor(RelationFeatureFactory featureFac,
java.lang.Boolean createUnrelatedRelations,
RelationMentionFactory factory) |
Modifier and Type | Method and Description |
---|---|
void |
annotate(Annotation dataset)
Annotates the given dataset with the current model This works in place,
i.e., it adds ExtractionObject objects to the sentences in the dataset To
make sure you are not messing with gold annotation create a copy of the
ExtractionDataSet first!
|
java.util.List<java.lang.String> |
annotateMulticlass(java.util.List<Datum<java.lang.String,java.lang.String>> testDatums) |
void |
annotateSentence(CoreMap sentence) |
protected java.lang.String |
classOf(Datum<java.lang.String,java.lang.String> datum,
ExtractionObject rel) |
protected GeneralDataset<java.lang.String,java.lang.String> |
createDataset(Annotation corpus) |
protected Datum<java.lang.String,java.lang.String> |
createDatum(RelationMention rel) |
protected Datum<java.lang.String,java.lang.String> |
createDatum(RelationMention rel,
java.lang.String label) |
protected java.util.List<RelationMention> |
extractAllRelations(CoreMap sentence)
Predict a relation for each pair of entities in the sentence; including relations of type unrelated.
|
protected void |
justificationOf(Datum<java.lang.String,java.lang.String> testDatum,
java.io.PrintWriter pw,
java.lang.String label) |
static BasicRelationExtractor |
load(java.lang.String modelPath) |
protected Counter<java.lang.String> |
probabilityOf(Datum<java.lang.String,java.lang.String> testDatum) |
protected static void |
reportWeights(LinearClassifier<java.lang.String,java.lang.String> classifier,
java.lang.String classLabel) |
void |
save(java.lang.String modelpath)
Serializes this extractor to a file
|
void |
setCreateUnrelatedRelations(boolean b) |
void |
setFeatureCountThreshold(int i) |
void |
setLoggerLevel(java.util.logging.Level level) |
void |
setRelationExtractorClassifierType(java.lang.String s) |
void |
setSigma(double d) |
void |
setValidator(LabelValidator lv) |
void |
train(Annotation sentences)
Train on a list of ExtractionSentence containing labeled RelationMention objects
|
void |
trainMulticlass(GeneralDataset<java.lang.String,java.lang.String> trainSet) |
protected LinearClassifier<java.lang.String,java.lang.String> classifier
@ArgumentParser.Option(name="featureCountThreshold", gloss="feature count threshold to apply to dataset") public int featureCountThreshold
@ArgumentParser.Option(name="featureFactory", gloss="Feature factory for the relation extractor") public RelationFeatureFactory featureFactory
@ArgumentParser.Option(name="sigma", gloss="strength of the prior on the linear classifier (passed to LinearClassifierFactory) or the C constant if relationExtractorClassifierType=svm") public double sigma
public java.lang.String relationExtractorClassifierType
protected boolean createUnrelatedRelations
protected RelationMentionFactory relationMentionFactory
public BasicRelationExtractor(RelationFeatureFactory featureFac, java.lang.Boolean createUnrelatedRelations, RelationMentionFactory factory)
public void setValidator(LabelValidator lv)
public void setRelationExtractorClassifierType(java.lang.String s)
public void setFeatureCountThreshold(int i)
public void setSigma(double d)
public void setCreateUnrelatedRelations(boolean b)
public static BasicRelationExtractor load(java.lang.String modelPath) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public void save(java.lang.String modelpath) throws java.io.IOException
Extractor
public void train(Annotation sentences)
public void trainMulticlass(GeneralDataset<java.lang.String,java.lang.String> trainSet)
protected static void reportWeights(LinearClassifier<java.lang.String,java.lang.String> classifier, java.lang.String classLabel)
protected java.lang.String classOf(Datum<java.lang.String,java.lang.String> datum, ExtractionObject rel)
protected Counter<java.lang.String> probabilityOf(Datum<java.lang.String,java.lang.String> testDatum)
protected void justificationOf(Datum<java.lang.String,java.lang.String> testDatum, java.io.PrintWriter pw, java.lang.String label)
protected java.util.List<RelationMention> extractAllRelations(CoreMap sentence)
public java.util.List<java.lang.String> annotateMulticlass(java.util.List<Datum<java.lang.String,java.lang.String>> testDatums)
public void annotateSentence(CoreMap sentence)
public void annotate(Annotation dataset)
Extractor
protected GeneralDataset<java.lang.String,java.lang.String> createDataset(Annotation corpus)
protected Datum<java.lang.String,java.lang.String> createDatum(RelationMention rel)
protected Datum<java.lang.String,java.lang.String> createDatum(RelationMention rel, java.lang.String label)
public void setLoggerLevel(java.util.logging.Level level)
setLoggerLevel
in interface Extractor