use of org.apache.jena.query.text.TextIndexException in project jena by apache.
the class DefineAnalyzersAssembler method open.
public static boolean open(Assembler a, Resource list) {
Resource current = list;
boolean isMultilingualSupport = false;
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.pAnalyzer)) {
Statement analyzerStmt = adding.getProperty(TextVocab.pAnalyzer);
RDFNode analyzerNode = analyzerStmt.getObject();
if (!analyzerNode.isResource()) {
throw new TextIndexException("addAnalyzers text:analyzer must be an analyzer spec resource: " + analyzerNode);
}
// calls GenericAnalyzerAssembler
Analyzer analyzer = (Analyzer) a.open((Resource) analyzerNode);
if (adding.hasProperty(TextVocab.pDefAnalyzer)) {
Statement defStmt = adding.getProperty(TextVocab.pDefAnalyzer);
Resource id = defStmt.getResource();
if (id.getURI() != null) {
Util.defineAnalyzer(id, analyzer);
} else {
throw new TextIndexException("addAnalyzers text:defineAnalyzer property must be a uri resource: " + adding);
}
}
if (adding.hasProperty(TextVocab.pAddLang)) {
Statement langStmt = adding.getProperty(TextVocab.pAddLang);
String langCode = langStmt.getString();
if (StringUtils.isNotBlank(langCode)) {
Util.addAnalyzer(langCode, analyzer);
isMultilingualSupport = true;
if (adding.hasProperty(TextVocab.pSearchFor)) {
Statement searchForStmt = adding.getProperty(TextVocab.pSearchFor);
List<String> tags = getStringList(searchForStmt, "text:searchFor");
Util.addSearchForTags(langCode, tags);
}
if (adding.hasProperty(TextVocab.pAuxIndex)) {
Statement auxIndexStmt = adding.getProperty(TextVocab.pAuxIndex);
List<String> tags = getStringList(auxIndexStmt, "text:auxIndex");
Util.addAuxIndexes(langCode, tags);
log.trace("addAuxIndexes for {} with tags: {}", langCode, tags);
}
if (adding.hasProperty(TextVocab.pIndexAnalyzer)) {
Statement indexStmt = adding.getProperty(TextVocab.pIndexAnalyzer);
Resource key = indexStmt.getResource();
Analyzer indexer = Util.getDefinedAnalyzer(key);
Util.addIndexAnalyzer(langCode, indexer);
log.trace("addIndexAnalyzer lang: {} with analyzer: {}", langCode, indexer);
}
} else {
throw new TextIndexException("text:addLang property must be a non-blank string: " + adding);
}
}
}
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;
}
Util.finishCaching();
return isMultilingualSupport;
}
use of org.apache.jena.query.text.TextIndexException in project jena by apache.
the class DefineAnalyzersAssembler method getStringList.
private static List<String> getStringList(Statement stmt, String p) {
List<String> tags = new ArrayList<String>();
RDFNode aNode = stmt.getObject();
if (!aNode.isResource()) {
throw new TextIndexException(p + " property is not a list : " + aNode);
}
Resource current = (Resource) aNode;
while (current != null && !current.equals(RDF.nil)) {
Statement firstStmt = current.getProperty(RDF.first);
if (firstStmt == null) {
throw new TextIndexException(p + " list not well formed: " + current);
}
RDFNode first = firstStmt.getObject();
if (!first.isLiteral()) {
throw new TextIndexException(p + " list not a String : " + first);
}
String tag = first.toString();
tags.add(tag);
Statement restStmt = current.getProperty(RDF.rest);
if (restStmt == null) {
throw new TextIndexException(p + " list not terminated by rdf:nil");
}
RDFNode rest = restStmt.getObject();
if (!rest.isResource()) {
throw new TextIndexException(p + " list rest node is not a resource : " + rest);
}
current = (Resource) rest;
}
return tags;
}
use of org.apache.jena.query.text.TextIndexException in project jena by apache.
the class PropListsAssembler method open.
public static void open(Assembler assembler, Resource list) {
Resource current = list;
while (current != null && !current.equals(RDF.nil)) {
Statement firstStmt = current.getProperty(RDF.first);
if (firstStmt == null) {
throw new TextIndexException("text:propLists list not well formed: " + current);
}
RDFNode first = firstStmt.getObject();
if (!first.isResource()) {
throw new TextIndexException("text:propLists element must be an anon resource : " + first);
}
// process the current list element to add a property list
Resource adding = (Resource) first;
if (adding.hasProperty(TextVocab.pPropListProp)) {
Statement propListPropStmt = adding.getProperty(TextVocab.pPropListProp);
RDFNode propListPropNode = propListPropStmt.getObject();
if (!propListPropNode.isResource()) {
throw new TextIndexException("text:propLists text:propListProp must be a resource: " + propListPropNode);
}
if (adding.hasProperty(TextVocab.pProps)) {
Statement propsStmt = adding.getProperty(TextVocab.pProps);
List<Resource> props = getPropsList(propsStmt);
Util.addPropsList((Resource) propListPropNode, props);
}
} else {
throw new TextIndexException("text:propLists text:propListProp must be a resource: " + adding.getProperty(TextVocab.pPropListProp));
}
Statement restStmt = current.getProperty(RDF.rest);
if (restStmt == null) {
throw new TextIndexException("text:propLists list not terminated by rdf:nil");
}
RDFNode rest = restStmt.getObject();
if (!rest.isResource()) {
throw new TextIndexException("text:propLists list rest is not a resource : " + rest);
}
current = (Resource) rest;
}
}
use of org.apache.jena.query.text.TextIndexException in project jena by apache.
the class ConfigurableAnalyzer method getTokenizer.
private Tokenizer getTokenizer(String tokenizerName) {
TokenizerSpec spec = tokenizerSpecs.get(tokenizerName);
if (spec == null) {
throw new TextIndexException("Unknown tokenizer : " + tokenizerName);
}
Class<?> clazz = spec.clazz;
Class<?>[] paramClasses = spec.paramClasses;
Object[] paramValues = spec.paramValues;
return newTokenizer(clazz, paramClasses, paramValues);
}
use of org.apache.jena.query.text.TextIndexException 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);
}
Aggregations