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);
}
}
use of org.opensextant.ConfigException in project Xponents by OpenSextant.
the class SolrProxy method setupCore.
/**
* Creates an EmbeddedSolrServer given solr home & 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);
}
}
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");
}
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();
}
}
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");
}
}
Aggregations