use of org.apache.jena.query.text.assembler.GenericFilterAssembler.FilterSpec in project jena by apache.
the class ConfigurableAnalyzer method getTokenFilter.
private TokenFilter getTokenFilter(String filterName, TokenStream source) {
FilterSpec spec = filterSpecs.get(filterName);
if (spec == null) {
throw new TextIndexException("Unknown filter : " + filterName);
}
Class<?> clazz = spec.clazz;
Class<?>[] paramClasses = spec.paramClasses;
Object[] paramValues = spec.paramValues;
// the source should always be the first parameter
paramValues[0] = source;
return newFilter(clazz, paramClasses, paramValues);
}
use of org.apache.jena.query.text.assembler.GenericFilterAssembler.FilterSpec in project jena by apache.
the class DefineFiltersAssembler method open.
/*
<#indexLucene> a text:TextIndexLucene ;
text:directory <file:Lucene> ;
text:entityMap <#entMap> ;
text:defineAnalyzers (
[text:addLang "sa-x-iast" ;
text:analyzer [ . . . ]]
[text:defineAnalyzer <#foo> ;
text:analyzer [ . . . ]]
[text:defineFilter <#bar> ;
text:filter [ . . . ]]
[text:defineTokenizer <#baz> ;
text:tokenizer [ . . . ]]
)
*/
public static boolean open(Assembler a, Resource list) {
Resource current = list;
while (current != null && !current.equals(RDF.nil)) {
Statement firstStmt = current.getProperty(RDF.first);
if (firstStmt == null) {
throw new TextIndexException("parameter list not well formed: " + current);
}
RDFNode first = firstStmt.getObject();
if (!first.isResource()) {
throw new TextIndexException("parameter specification must be an anon resource : " + first);
}
// process the current list element to add an analyzer
Resource adding = (Resource) first;
if (adding.hasProperty(TextVocab.pFilter)) {
Statement filterStmt = adding.getProperty(TextVocab.pFilter);
RDFNode filterNode = filterStmt.getObject();
if (!filterNode.isResource()) {
throw new TextIndexException("addFilters text:filter must be a filter spec resource: " + filterNode);
}
// calls GenericFilterAssembler
FilterSpec filterSpec = (FilterSpec) a.open((Resource) filterNode);
if (adding.hasProperty(TextVocab.pDefFilter)) {
Statement defStmt = adding.getProperty(TextVocab.pDefFilter);
Resource id = defStmt.getResource();
if (id.getURI() != null) {
ConfigurableAnalyzer.defineFilter(id.getURI(), filterSpec);
} else {
throw new TextIndexException("text:defineFilters text:defineAnalyzer property must be a non-blank resource: " + adding);
}
} else {
Log.warn("DefineFiltersAssembler", "Filter specified but no text:defineFilter so filter is not accessible!");
}
}
Statement restStmt = current.getProperty(RDF.rest);
if (restStmt == null) {
throw new TextIndexException("parameter list not terminated by rdf:nil");
}
RDFNode rest = restStmt.getObject();
if (!rest.isResource()) {
throw new TextIndexException("parameter list node is not a resource : " + rest);
}
current = (Resource) rest;
}
return true;
}
Aggregations