use of org.opensextant.extractors.flexpat.PatternTestCase in project Xponents by OpenSextant.
the class TestPoLiReporter method testUserFile.
/**
* Run patterns over a single file using a pre-configured PoLi. Use -c
* config -u file test
*/
public void testUserFile(String f) throws IOException, NormalizationException {
// poli.configure(new File(f));
String fname = FilenameUtils.getBaseName(f);
createResultsFile("results/test_" + fname + ".csv");
// List<TextMatch> allResults = new ArrayList<>();
log.info("TESTING FILE: " + f);
for (PatternTestCase test : poli.getPatternManager().testcases) {
log.info("TEST " + test.id);
TextMatchResult results = poli.extract_patterns(test.text, test.id, test.family);
if (results.evaluated && !results.matches.isEmpty()) {
try {
for (TextMatch m : results.matches) {
// log.debug("TEST " + test.id + " FOUND: " +
// m.toString());
Map<String, Object> row = createResultRow(test, m);
report.write(row, header, poliResultsSpec);
}
} catch (IOException ioerr) {
log.error("Failed to write result for " + test.id, ioerr);
}
} else {
log.info("TEST " + test.id + " STATUS: FAILED");
}
}
String inputText = FileUtils.readFileToString(new File(f));
poli.enableAll();
String fileID = "FILE:" + fname;
PatternTestCase fileTestCase = new PatternTestCase(fileID, "all", "(file text)");
TextMatchResult results = poli.extract_patterns(inputText, fileID, null);
if (results.evaluated && !results.matches.isEmpty()) {
try {
for (TextMatch m : results.matches) {
// log.debug("TEST " + test.id + " FOUND: " +
// m.toString());
Map<String, Object> row = createResultRow(fileTestCase, m);
report.write(row, header, poliResultsSpec);
}
} catch (IOException ioerr) {
log.error("Failed to write result for " + fileID, ioerr);
}
} else {
log.info("FILE TEST " + fileID + " STATUS: FAILED");
}
closeReport();
}
use of org.opensextant.extractors.flexpat.PatternTestCase in project Xponents by OpenSextant.
the class TestXCoord method systemTests.
/**
* Using the TestUtility, all patterns are tested and reported to the
* results folder.
*/
public void systemTests() {
RegexPatternManager mgr = xcoord.getPatternManager();
log.info("\n\n=== SYSTEM TESTS ===\n\n");
if (!mgr.testing) {
log.info("TESTING OFF -- TURN ON DEBUG in LOG4J");
return;
}
xcoord.match_UTM(true);
xcoord.match_MGRS(true);
xcoord.match_DD(true);
xcoord.match_DMS(true);
xcoord.match_DM(true);
try {
TestXCoordReporter tester = new TestXCoordReporter("./results/xcoord_System.csv");
for (PatternTestCase tst : mgr.testcases) {
TextMatchResult results = xcoord.extract_coordinates(tst.text, tst.id, tst.family_id);
results.add_trace("Test Payload: " + tst.text);
if (!results.evaluated) {
continue;
}
log.info("=========SYSTEM TEST " + tst.id + " FOUND:" + (results.matches.isEmpty() ? "NOTHING" : results.matches.size()));
tester.save_result(null, results);
}
tester.close_report();
} catch (Exception err) {
log.error("Not finishing tests", err);
return;
}
log.info("=== SYSTEM TESTS DONE ===");
}
use of org.opensextant.extractors.flexpat.PatternTestCase in project Xponents by OpenSextant.
the class TestPoLiReporter method test.
/**
* System tests
*/
public void test() throws IOException {
poli.enableAll();
createResultsFile("results/test_System.csv");
// List<TextMatch> allResults = new ArrayList<>();
log.info("TESTING ALL SYSTEM PATTERNS");
for (PatternTestCase test : this.poli.getPatternManager().testcases) {
log.info("TEST " + test.id);
TextMatchResult results = this.poli.extract_patterns(test.text, test.id, test.family);
if (results.evaluated && !results.matches.isEmpty()) {
try {
for (TextMatch m : results.matches) {
// log.debug("TEST " + test.id + " FOUND: " +
// m.toString());
Map<String, Object> row = createResultRow(test, m);
report.write(row, header, poliResultsSpec);
}
} catch (IOException ioerr) {
log.error("Failed to write result for " + test.id, ioerr);
}
} else {
Map<String, Object> row = createResultRow(test, null);
report.write(row, header, poliResultsSpec);
log.info("TEST " + test.id + " STATUS: FAILED");
}
}
closeReport();
}
use of org.opensextant.extractors.flexpat.PatternTestCase in project Xponents by OpenSextant.
the class TestXTemporal method systemTests.
/**
*
*/
public void systemTests() {
log.info("=== SYSTEM TESTS START ===");
// Enable select patterns: disable all first, then enable pattern families.
// xdt.disableAll();
// xdt.match_MonDayYear(true);
// xdt.match_DateTime(true);
// xdt.match_MonDayYear(true);
xdt.enableAll();
try {
TestXTemporalReporter tester = new TestXTemporalReporter("./results/xtemp_System.csv");
for (PatternTestCase tst : xdt.getPatternManager().testcases) {
TextMatchResult results = xdt.extract_dates(tst.text, tst.id);
results.add_trace("Test Payload: " + tst.text);
if (!results.evaluated) {
continue;
}
log.info("=========SYSTEM TEST " + tst.id + " FOUND:" + (results.matches == null ? "NOTHING" : results.matches.size()));
tester.save_result(results);
}
tester.close_report();
} catch (Exception err) {
log.error("Not finishing tests", err);
return;
}
log.info("=== SYSTEM TESTS DONE ===");
}
Aggregations