Search in sources :

Example 1 with PatternTestCase

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();
}
Also used : PatternTestCase(org.opensextant.extractors.flexpat.PatternTestCase) TextMatch(org.opensextant.extraction.TextMatch) IOException(java.io.IOException) TextMatchResult(org.opensextant.extractors.flexpat.TextMatchResult) File(java.io.File)

Example 2 with PatternTestCase

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 ===");
}
Also used : PatternTestCase(org.opensextant.extractors.flexpat.PatternTestCase) TextMatchResult(org.opensextant.extractors.flexpat.TextMatchResult) RegexPatternManager(org.opensextant.extractors.flexpat.RegexPatternManager) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with PatternTestCase

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();
}
Also used : PatternTestCase(org.opensextant.extractors.flexpat.PatternTestCase) TextMatch(org.opensextant.extraction.TextMatch) IOException(java.io.IOException) TextMatchResult(org.opensextant.extractors.flexpat.TextMatchResult)

Example 4 with PatternTestCase

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 ===");
}
Also used : PatternTestCase(org.opensextant.extractors.flexpat.PatternTestCase) TextMatchResult(org.opensextant.extractors.flexpat.TextMatchResult) ConfigException(org.opensextant.ConfigException)

Aggregations

PatternTestCase (org.opensextant.extractors.flexpat.PatternTestCase)4 TextMatchResult (org.opensextant.extractors.flexpat.TextMatchResult)4 IOException (java.io.IOException)3 TextMatch (org.opensextant.extraction.TextMatch)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 ConfigException (org.opensextant.ConfigException)1 RegexPatternManager (org.opensextant.extractors.flexpat.RegexPatternManager)1