use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class QuerySolutionMap method addAll.
/** Add all of the solutions from one QuerySolution into this QuerySolutionMap */
public void addAll(QuerySolution other) {
Iterator<String> iter = other.varNames();
for (; iter.hasNext(); ) {
String vName = iter.next();
RDFNode rdfNode = other.get(vName);
map.put(vName, rdfNode);
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class TestSyntaxTransform method testQueryModel.
private void testQueryModel(String input, String output, String varStr, String valStr) {
Query q1 = QueryFactory.create(PREFIX + input);
Query qExpected = QueryFactory.create(PREFIX + output);
Map<String, RDFNode> map = new HashMap<>();
Node n = SSE.parseNode(valStr);
RDFNode x = ModelUtils.convertGraphNodeToRDFNode(n);
map.put(varStr, x);
Query qTrans = QueryTransformOps.transformQuery(q1, map);
assertEquals(qExpected, qTrans);
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class JenaPreparedStatement method setObject.
@Override
public void setObject(int parameterIndex, Object value) throws SQLException {
if (value == null)
throw new SQLException("Setting a null value is not permitted");
if (value instanceof Node) {
this.setParameter(parameterIndex, (Node) value);
} else if (value instanceof RDFNode) {
this.setParameter(parameterIndex, ((RDFNode) value).asNode());
} else if (value instanceof String) {
this.setParameter(parameterIndex, NodeFactory.createLiteral((String) value));
} else if (value instanceof Boolean) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(Boolean.toString((Boolean) value), XSDDatatype.XSDboolean));
} else if (value instanceof Long) {
this.setParameter(parameterIndex, NodeFactoryExtra.intToNode((Long) value));
} else if (value instanceof Integer) {
this.setParameter(parameterIndex, NodeFactoryExtra.intToNode((Integer) value));
} else if (value instanceof Short) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(Short.toString((Short) value), XSDDatatype.XSDshort));
} else if (value instanceof Byte) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(Byte.toString((Byte) value), XSDDatatype.XSDbyte));
} else if (value instanceof BigDecimal) {
this.setParameter(parameterIndex, NodeFactory.createLiteral(((BigDecimal) value).toPlainString(), XSDDatatype.XSDdecimal));
} else if (value instanceof Float) {
this.setParameter(parameterIndex, NodeFactoryExtra.floatToNode((Float) value));
} else if (value instanceof Double) {
this.setParameter(parameterIndex, NodeFactoryExtra.doubleToNode((Double) value));
} else if (value instanceof Date) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(((Date) value).getTime());
this.setParameter(parameterIndex, NodeFactoryExtra.dateTimeToNode(c));
} else if (value instanceof Time) {
Calendar c = Calendar.getInstance();
c.setTimeInMillis(((Time) value).getTime());
this.setParameter(parameterIndex, NodeFactoryExtra.timeToNode(c));
} else if (value instanceof Calendar) {
this.setParameter(parameterIndex, NodeFactoryExtra.dateTimeToNode((Calendar) value));
} else if (value instanceof URL) {
this.setParameter(parameterIndex, NodeFactory.createURI(value.toString()));
} else if (value instanceof URI) {
this.setParameter(parameterIndex, NodeFactory.createURI(value.toString()));
} else if (value instanceof IRI) {
this.setParameter(parameterIndex, NodeFactory.createURI(value.toString()));
} else {
throw new SQLException("setObject() received a value that could not be converted to a RDF node for use in a SPARQL query");
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class TextIndexLuceneAssembler method open.
/*
<#index> a :TextIndexLucene ;
#text:directory "mem" ;
#text:directory "DIR" ;
text:directory <file:DIR> ;
text:entityMap <#endMap> ;
.
*/
@SuppressWarnings("resource")
@Override
public TextIndex open(Assembler a, Resource root, Mode mode) {
try {
if (!GraphUtils.exactlyOneProperty(root, pDirectory))
throw new TextIndexException("No 'text:directory' property on " + root);
Directory directory;
RDFNode n = root.getProperty(pDirectory).getObject();
if (n.isLiteral()) {
String literalValue = n.asLiteral().getLexicalForm();
if (literalValue.equals("mem")) {
directory = new RAMDirectory();
} else {
File dir = new File(literalValue);
directory = FSDirectory.open(dir.toPath());
}
} else {
Resource x = n.asResource();
String path = IRILib.IRIToFilename(x.getURI());
File dir = new File(path);
directory = FSDirectory.open(dir.toPath());
}
Analyzer analyzer = null;
Statement analyzerStatement = root.getProperty(pAnalyzer);
if (null != analyzerStatement) {
RDFNode aNode = analyzerStatement.getObject();
if (!aNode.isResource()) {
throw new TextIndexException("Text analyzer property is not a resource : " + aNode);
}
Resource analyzerResource = (Resource) aNode;
analyzer = (Analyzer) a.open(analyzerResource);
}
Analyzer queryAnalyzer = null;
Statement queryAnalyzerStatement = root.getProperty(pQueryAnalyzer);
if (null != queryAnalyzerStatement) {
RDFNode qaNode = queryAnalyzerStatement.getObject();
if (!qaNode.isResource()) {
throw new TextIndexException("Text query analyzer property is not a resource : " + qaNode);
}
Resource analyzerResource = (Resource) qaNode;
queryAnalyzer = (Analyzer) a.open(analyzerResource);
}
String queryParser = null;
Statement queryParserStatement = root.getProperty(pQueryParser);
if (null != queryParserStatement) {
RDFNode qpNode = queryParserStatement.getObject();
if (!qpNode.isResource()) {
throw new TextIndexException("Text query parser property is not a resource : " + qpNode);
}
Resource parserResource = (Resource) qpNode;
queryParser = parserResource.getLocalName();
}
boolean isMultilingualSupport = false;
Statement mlSupportStatement = root.getProperty(pMultilingualSupport);
if (null != mlSupportStatement) {
RDFNode mlsNode = mlSupportStatement.getObject();
if (!mlsNode.isLiteral()) {
throw new TextIndexException("text:multilingualSupport property must be a string : " + mlsNode);
}
isMultilingualSupport = mlsNode.asLiteral().getBoolean();
}
boolean storeValues = false;
Statement storeValuesStatement = root.getProperty(pStoreValues);
if (null != storeValuesStatement) {
RDFNode svNode = storeValuesStatement.getObject();
if (!svNode.isLiteral()) {
throw new TextIndexException("text:storeValues property must be a string : " + svNode);
}
storeValues = svNode.asLiteral().getBoolean();
}
Resource r = GraphUtils.getResourceValue(root, pEntityMap);
EntityDefinition docDef = (EntityDefinition) a.open(r);
TextIndexConfig config = new TextIndexConfig(docDef);
config.setAnalyzer(analyzer);
config.setQueryAnalyzer(queryAnalyzer);
config.setQueryParser(queryParser);
config.setMultilingualSupport(isMultilingualSupport);
config.setValueStored(storeValues);
return TextDatasetFactory.createLuceneIndex(directory, config);
} catch (IOException e) {
IO.exception(e);
return null;
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class ConfigurableAnalyzerAssembler method toFilterList.
private List<String> toFilterList(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("filter list not well formed");
}
RDFNode node = stmt.getObject();
if (!node.isResource()) {
throw new TextIndexException("filter is not a resource : " + node);
}
result.add(node.asResource().getLocalName());
stmt = current.getProperty(RDF.rest);
if (stmt == null) {
throw new TextIndexException("filter list not terminated by rdf:nil");
}
node = stmt.getObject();
if (!node.isResource()) {
throw new TextIndexException("filter list node is not a resource : " + node);
}
current = node.asResource();
}
return result;
}
Aggregations