Search in sources :

Example 16 with ConfigException

use of org.opensextant.ConfigException in project Xponents by OpenSextant.

the class TagFilter method loadExclusions.

/**
     * Exclusions have two columns in a CSV file. 'exclusion', 'category'
     *
     * "#" in exclusion column implies a comment.
     * Call is responsible for getting I/O stream.
     *  
     * @param filestream
     *            URL/file with exclusion terms
     * @return set of filter terms
     * @throws ConfigException
     *             if filter is not found
     */
public static Set<String> loadExclusions(InputStream filestream) throws ConfigException {
    /*
         * Load the exclusion names -- these are terms that are gazeteer
         * entries, e.g., gazetteer.name = <exclusion term>, that will be marked
         * as search_only = true.
         */
    try (Reader termsIO = new InputStreamReader(filestream)) {
        CsvMapReader termreader = new CsvMapReader(termsIO, CsvPreference.EXCEL_PREFERENCE);
        String[] columns = termreader.getHeader(true);
        Map<String, String> terms = null;
        HashSet<String> stopTerms = new HashSet<String>();
        while ((terms = termreader.read(columns)) != null) {
            String term = terms.get("exclusion");
            if (StringUtils.isBlank(term) || term.startsWith("#")) {
                continue;
            }
            stopTerms.add(term.toLowerCase().trim());
        }
        termreader.close();
        return stopTerms;
    } catch (Exception err) {
        throw new ConfigException("Could not load exclusions.", err);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) CsvMapReader(org.supercsv.io.CsvMapReader) CsvMapReader(org.supercsv.io.CsvMapReader) ConfigException(org.opensextant.ConfigException) ConfigException(org.opensextant.ConfigException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 17 with ConfigException

use of org.opensextant.ConfigException in project Xponents by OpenSextant.

the class SolrProxy method setupCore.

/**
     * Creates an EmbeddedSolrServer given solr home &amp; the core to use.
     * These may be null and you get the default.
     *
     * @param _solrHome  solr home
     * @param _coreName  name of core
     * @return the embedded solr server
     * @throws ConfigException on err
     */
public static EmbeddedSolrServer setupCore(String _solrHome, String _coreName) throws ConfigException {
    try {
        CoreContainer solrContainer;
        if (_solrHome == null) {
            solrContainer = new CoreContainer();
        } else {
            solrContainer = new CoreContainer(_solrHome);
        }
        // since Solr 4.4
        solrContainer.load();
        return new EmbeddedSolrServer(solrContainer, _coreName);
    } catch (Exception err) {
        throw new ConfigException("Failed to set up Embedded Solr at " + _solrHome + " CORE:" + _coreName, err);
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) ConfigException(org.opensextant.ConfigException) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) MalformedURLException(java.net.MalformedURLException) ConfigException(org.opensextant.ConfigException) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException)

Example 18 with ConfigException

use of org.opensextant.ConfigException in project Xponents by OpenSextant.

the class KeywordTaggerMapper method setup.

/**
     * Setup.  XTax or PlaceGecoder takes in SOLR path for xponents solr from JVM environment.
     */
@Override
public void setup(Context c) throws IOException {
    super.setup(c);
    try {
        xtax = new TaxonMatcher();
    } catch (ConfigException e) {
        // TODO Auto-generated catch block
        throw new IOException("setup.XTax", e);
    }
    log.info("DONE");
}
Also used : ConfigException(org.opensextant.ConfigException) TaxonMatcher(org.opensextant.extractors.xtax.TaxonMatcher) IOException(java.io.IOException)

Example 19 with ConfigException

use of org.opensextant.ConfigException in project Xponents by OpenSextant.

the class TestPoLi method main.

/**
     * Run a simple test.
     * 
     * @param args
     *            only one argument accepted: a text file input.
     */
public static void main(String[] args) {
    boolean debug = true;
    boolean systemTest = false;
    String testFile = null;
    String config = null;
    try {
        gnu.getopt.Getopt opts = new gnu.getopt.Getopt("Poli", args, "c:u:f");
        int c;
        while ((c = opts.getopt()) != -1) {
            switch(c) {
                case 'f':
                    System.out.println("\tSystem TESTS======= ");
                    systemTest = true;
                    break;
                case 'u':
                    testFile = opts.getOptarg();
                    System.out.println("\tUser TESTS======= FILE=" + testFile);
                    break;
                case 'c':
                    config = opts.getOptarg();
                    System.out.println("\tUser Patterns Configuration ======= FILE=" + config);
                    break;
                default:
                    TestPoLi.usage();
                    System.exit(1);
            }
        }
    } catch (Exception runErr) {
        runErr.printStackTrace();
        TestPoLi.usage();
        System.exit(1);
    }
    PatternsOfLife poli = null;
    try {
        // Use default config file.
        poli = new PatternsOfLife(debug);
        if (config == null) {
            // default
            poli.configure();
        } else {
            poli.configure(config);
        }
    } catch (ConfigException xerr) {
        xerr.printStackTrace();
        System.exit(-1);
    }
    try {
        TestPoLiReporter test = new TestPoLiReporter(poli);
        if (systemTest) {
            test.test();
        } else if (testFile != null) {
            test.testUserFile(testFile);
        }
    } catch (NormalizationException xerr) {
        xerr.printStackTrace();
    } catch (IOException ioerr) {
        ioerr.printStackTrace();
    }
}
Also used : ConfigException(org.opensextant.ConfigException) IOException(java.io.IOException) ConfigException(org.opensextant.ConfigException) NormalizationException(org.opensextant.extraction.NormalizationException) IOException(java.io.IOException) NormalizationException(org.opensextant.extraction.NormalizationException) PatternsOfLife(org.opensextant.extractors.poli.PatternsOfLife)

Example 20 with ConfigException

use of org.opensextant.ConfigException in project Xponents by OpenSextant.

the class TestPersonFilter method test.

@Test
public void test() {
    // Set classpath to point to ./gazetteer/conf
    URL p1 = PlaceGeocoder.class.getResource("/filters/person-name-filter.txt");
    URL p2 = PlaceGeocoder.class.getResource("/filters/person-title-filter.txt");
    URL p3 = PlaceGeocoder.class.getResource("/filters/person-suffix-filter.txt");
    try {
        PersonNameFilter filt = new PersonNameFilter(p1, p2, p3);
        PlaceCandidate p = new PlaceCandidate();
        p.setText("John Doe");
        p.setPrematchTokens(null);
        p.setPostmatchTokens(null);
        filt.evaluate(p, null);
        print(p.getText() + " pass? " + p.isFilteredOut());
        p.setPrematchTokens("             ".split(" "));
        p.setPostmatchTokens("             ".split(" "));
        filt.evaluate(p, null);
        print(p.getText() + " pass? " + p.isFilteredOut());
        p.setPrematchTokens("this is Mr. ".split(" "));
        p.setPostmatchTokens(null);
        filt.evaluate(p, null);
        print(p.getText() + " pass? " + p.isFilteredOut());
        p.setPrematchTokens("this is Mr. ".split(" "));
        p.setPostmatchTokens(" and his wife lives in the city...".split(" "));
        filt.evaluate(p, null);
        print(p.getText() + " pass? " + p.isFilteredOut());
    } catch (ConfigException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        fail("Configuration problem -- set CLASSPATH to include ./conf");
    }
}
Also used : ConfigException(org.opensextant.ConfigException) PersonNameFilter(org.opensextant.extractors.geo.rules.PersonNameFilter) URL(java.net.URL) PlaceCandidate(org.opensextant.extractors.geo.PlaceCandidate) Test(org.junit.Test)

Aggregations

ConfigException (org.opensextant.ConfigException)28 IOException (java.io.IOException)20 File (java.io.File)5 URL (java.net.URL)4 MimeTypeParseException (javax.activation.MimeTypeParseException)3 MessagingException (javax.mail.MessagingException)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)3 PlaceGeocoder (org.opensextant.extractors.geo.PlaceGeocoder)3 XText (org.opensextant.xtext.XText)3 PSTFile (com.pff.PSTFile)2 MalformedURLException (java.net.MalformedURLException)2 HashSet (java.util.HashSet)2 TextMatch (org.opensextant.extraction.TextMatch)2 PersonNameFilter (org.opensextant.extractors.geo.rules.PersonNameFilter)2 TaxonMatcher (org.opensextant.extractors.xtax.TaxonMatcher)2 XTemporal (org.opensextant.extractors.xtemporal.XTemporal)2 PSTException (com.pff.PSTException)1 LongOpt (gnu.getopt.LongOpt)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1