Search in sources :

Example 1 with GeocoordTestCase

use of org.opensextant.extractors.xcoord.GeocoordTestCase in project Xponents by OpenSextant.

the class TestXCoord method fileTestByLines.

/**
     * This will accomodate any test file that has at least the following style:
     *
     * FAMILY-XXX COORDINATE TEXT "FAIL"
     *
     * Where the first FAMILY token is
     *
     * @param coordfile
     */
public void fileTestByLines(String coordfile) {
    xcoord.match_UTM(true);
    xcoord.match_MGRS(true);
    xcoord.match_DD(true);
    xcoord.match_DMS(true);
    xcoord.match_DM(true);
    try {
        String _file = coordfile.trim();
        String fname = FilenameUtils.getBaseName(_file);
        TestXCoordReporter tester = new TestXCoordReporter("./results/xcoord_" + fname + "-lines.csv");
        java.io.LineNumberReader in = getLineReader(coordfile);
        String line = null;
        while ((line = in.readLine()) != null) {
            String text = line.trim();
            if (text.startsWith("#")) {
                continue;
            }
            if (text.isEmpty()) {
                continue;
            }
            String fam = find_family(line);
            int famx = XConstants.get_CCE_family(fam);
            if (famx == XConstants.UNK_PATTERN) {
                log.error("Unknown test pattern TEXT=" + text);
                continue;
            }
            GeocoordTestCase tst = new GeocoordTestCase("#" + in.getLineNumber(), fam, text);
            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("=========FILE TEST " + tst.id + " FOUND:" + (results.matches.isEmpty() ? "NOTHING" : results.matches.size()));
            tester.save_result(tst, results);
        }
        tester.close_report();
        log.info("=== FILE TESTS DONE ===");
    } catch (Exception err) {
        log.error("TEST BY LINES", err);
    }
}
Also used : GeocoordTestCase(org.opensextant.extractors.xcoord.GeocoordTestCase) LineNumberReader(java.io.LineNumberReader) TextMatchResult(org.opensextant.extractors.flexpat.TextMatchResult) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with GeocoordTestCase

use of org.opensextant.extractors.xcoord.GeocoordTestCase in project Xponents by OpenSextant.

the class TestXCoord method fileTruth.

/**
     * This will accomodate any test file that has at least the following style:
     *
     * FAMILY-XXX COORDINATE TEXT "FAIL"
     *
     * Where the first FAMILY token is
     *
     * @param coordfile
     */
public void fileTruth(File coordfile) {
    xcoord.match_UTM(true);
    xcoord.match_MGRS(true);
    xcoord.match_DD(true);
    xcoord.match_DMS(true);
    xcoord.match_DM(true);
    try {
        //String _file = coordfile.trim();
        String fname = FilenameUtils.getBaseName(coordfile.getName());
        TestXCoordReporter tester = new TestXCoordReporter("./results/xcoord_" + fname + "-rows.csv");
        //
        tester.full_report = false;
        CsvMapReader in = open(coordfile);
        String text = null;
        int linenum = 0;
        String[] columns = in.getHeader(true);
        Map<String, String> testRow = null;
        // id, enumeration, test, true_lat, true_lon, remark
        while ((testRow = in.read(columns)) != null) {
            String patid = testRow.get("id");
            if (patid == null) {
                continue;
            }
            patid = patid.trim();
            if (patid.startsWith("#")) {
                continue;
            }
            if (patid.isEmpty()) {
                continue;
            }
            String fam = find_family(patid);
            int famx = XConstants.get_CCE_family(fam);
            if (famx == XConstants.UNK_PATTERN) {
                log.error("Unknown test pattern TEXT=" + text);
                continue;
            }
            text = testRow.get("enumeration");
            linenum = Integer.parseInt(text);
            text = testRow.get("test");
            text = text.replace("$NL", "\n");
            String rmks = testRow.get("remark");
            // "Patid # rowid" == test instance id
            // DMS07#12  -- 12th example of DMS07 test.
            //
            GeocoordTestCase tst = new GeocoordTestCase(patid + "#" + linenum, fam, text);
            tst.match.setLatitude(testRow.get("true_lat"));
            tst.match.setLongitude(testRow.get("true_lon"));
            tst.setRemarks(rmks);
            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("=========FILE TEST " + tst.id + " FOUND:" + (results.matches.isEmpty() ? "NOTHING" : results.matches.size()));
            tester.save_result(tst, results);
        }
        tester.close_report();
        log.info("=== FILE TESTS DONE ===");
    } catch (Exception err) {
        log.error("TEST BY LINES", err);
    }
}
Also used : GeocoordTestCase(org.opensextant.extractors.xcoord.GeocoordTestCase) CsvMapReader(org.supercsv.io.CsvMapReader) TextMatchResult(org.opensextant.extractors.flexpat.TextMatchResult) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 TextMatchResult (org.opensextant.extractors.flexpat.TextMatchResult)2 GeocoordTestCase (org.opensextant.extractors.xcoord.GeocoordTestCase)2 LineNumberReader (java.io.LineNumberReader)1 CsvMapReader (org.supercsv.io.CsvMapReader)1