Skip to content

Commit 5b62b0d

Browse files
yuhaozhangAngledLuffa
authored andcommitted
Update KBPEnsembleExtractor to allow empty statistical model
1 parent 41bebb2 commit 5b62b0d

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/edu/stanford/nlp/ie/KBPEnsembleExtractor.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,34 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
7474
RedwoodConfiguration.standard().apply(); // Disable SLF4J crap.
7575
ArgumentParser.fillOptions(KBPEnsembleExtractor.class, args);
7676

77-
Object object = IOUtils.readObjectFromURLOrClasspathOrFileSystem(STATISTICAL_MODEL);
7877
KBPRelationExtractor statisticalExtractor;
79-
if (object instanceof LinearClassifier) {
80-
//noinspection unchecked
81-
statisticalExtractor = new KBPStatisticalExtractor((Classifier<String, String>) object);
82-
} else if (object instanceof KBPStatisticalExtractor) {
83-
statisticalExtractor = (KBPStatisticalExtractor) object;
78+
if (STATISTICAL_MODEL.length() == 0) {
79+
logger.info("No statistical model will be used.");
80+
statisticalExtractor = null;
8481
} else {
85-
throw new ClassCastException(object.getClass() + " cannot be cast into a " + KBPStatisticalExtractor.class);
82+
Object object = IOUtils.readObjectFromURLOrClasspathOrFileSystem(STATISTICAL_MODEL);
83+
if (object instanceof LinearClassifier) {
84+
//noinspection unchecked
85+
statisticalExtractor = new KBPStatisticalExtractor((Classifier<String, String>) object);
86+
} else if (object instanceof KBPStatisticalExtractor) {
87+
statisticalExtractor = (KBPStatisticalExtractor) object;
88+
} else {
89+
throw new ClassCastException(object.getClass() + " cannot be cast into a " + KBPStatisticalExtractor.class);
90+
}
91+
logger.info("Read statistical model from " + STATISTICAL_MODEL);
92+
}
93+
94+
KBPRelationExtractor extractor;
95+
if (statisticalExtractor == null) {
96+
extractor = new KBPEnsembleExtractor(
97+
new KBPTokensregexExtractor(TOKENSREGEX_DIR),
98+
new KBPSemgrexExtractor(SEMGREX_DIR));
99+
} else {
100+
extractor = new KBPEnsembleExtractor(
101+
new KBPTokensregexExtractor(TOKENSREGEX_DIR),
102+
new KBPSemgrexExtractor(SEMGREX_DIR),
103+
statisticalExtractor);
86104
}
87-
logger.info("Read statistical model from " + STATISTICAL_MODEL);
88-
KBPRelationExtractor extractor = new KBPEnsembleExtractor(
89-
new KBPTokensregexExtractor(TOKENSREGEX_DIR),
90-
new KBPSemgrexExtractor(SEMGREX_DIR),
91-
statisticalExtractor
92-
);
93105

94106
List<Pair<KBPInput, String>> testExamples = KBPRelationExtractor.readDataset(TEST_FILE);
95107

0 commit comments

Comments
 (0)