use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class SecuredRDFNodeImpl method as.
@SuppressWarnings("unchecked")
@Override
public <T extends RDFNode> T as(final Class<T> view) throws ReadDeniedException, AuthenticationRequiredException, SecuredUnsupportedPolymorphismException {
checkRead();
// see if the base Item can as
T baseAs = holder.getBaseItem().as(view);
if (view.equals(SecuredRDFNodeImpl.class) || view.equals(RDFNode.class)) {
return (T) this;
}
final Method m = getConstructor(view);
if (m == null) {
throw new SecuredUnsupportedPolymorphismException(this, view);
}
try {
return (T) m.invoke(null, securedModel, baseAs);
} catch (final UnsupportedPolymorphismException e) {
throw new SecuredUnsupportedPolymorphismException(this, view);
} catch (final IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (final IllegalAccessException e) {
throw new RuntimeException(e);
} catch (final InvocationTargetException e) {
throw new RuntimeException(e);
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class SpatialIndexLuceneAssembler method open.
/*
<#index> a :SpatialIndexLucene ;
#spatial:directory "mem" ;
spatial:directory <file:DIR> ;
spatial:definition <#definition> ;
.
*/
@SuppressWarnings("resource")
@Override
public SpatialIndex open(Assembler a, Resource root, Mode mode) {
try {
if (!GraphUtils.exactlyOneProperty(root, pDirectory))
throw new SpatialIndexException("No 'spatial:directory' property on " + root);
Directory directory;
RDFNode n = root.getProperty(pDirectory).getObject();
if (n.isLiteral()) {
if (!"mem".equals(n.asLiteral().getLexicalForm()))
throw new SpatialIndexException("No 'spatial:directory' property on " + root + " is a literal and not \"mem\"");
directory = new RAMDirectory();
} else {
Resource x = n.asResource();
String path = IRILib.IRIToFilename(x.getURI());
File dir = new File(path);
directory = FSDirectory.open(dir.toPath());
}
Resource r = GraphUtils.getResourceValue(root, pDefinition);
EntityDefinition docDef = (EntityDefinition) a.open(r);
return SpatialDatasetFactory.createLuceneIndex(directory, docDef);
} catch (IOException e) {
IO.exception(e);
return null;
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class LocalizedAnalyzerAssembler method open.
/*
text:map (
[ text:field "text" ;
text:predicate rdfs:label;
text:analyzer [
a lucene:LocalizedAnalyzer ;
text:language "en" ;
]
.
*/
@Override
public Analyzer open(Assembler a, Resource root, Mode mode) {
if (root.hasProperty(TextVocab.pLanguage)) {
RDFNode node = root.getProperty(TextVocab.pLanguage).getObject();
if (!node.isLiteral()) {
throw new TextIndexException("text:language property must be a string : " + node);
}
String lang = node.toString();
return Util.getLocalizedAnalyzer(lang);
} else {
return new StandardAnalyzer();
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class StandardAnalyzerAssembler method toList.
private List<String> toList(Resource list) {
List<String> result = new ArrayList<>();
Resource current = list;
while (current != null && !current.equals(RDF.nil)) {
Statement stmt = current.getProperty(RDF.first);
if (stmt == null) {
throw new TextIndexException("stop word list not well formed");
}
RDFNode node = stmt.getObject();
if (!node.isLiteral()) {
throw new TextIndexException("stop word is not a literal : " + node);
}
result.add(((Literal) node).getLexicalForm());
stmt = current.getProperty(RDF.rest);
if (stmt == null) {
throw new TextIndexException("stop word list not terminated by rdf:nil");
}
node = stmt.getObject();
if (!node.isResource()) {
throw new TextIndexException("stop word list node is not a resource : " + node);
}
current = (Resource) node;
}
return result;
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class StandardAnalyzerAssembler method analyzerWithStopWords.
private Analyzer analyzerWithStopWords(Resource root) {
RDFNode node = root.getProperty(TextVocab.pStopWords).getObject();
if (!node.isResource()) {
throw new TextIndexException("text:stopWords property takes a list as a value : " + node);
}
CharArraySet stopWords = toCharArraySet((Resource) node);
return new StandardAnalyzer(stopWords);
}
Aggregations