use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestDatasetWithLuceneStoredLiterals method testLiteralValue.
@Test
public void testLiteralValue() {
// test basic capturing of the literal value in a variable
final String turtle = PF_DATA;
String queryString = StrUtils.strjoinNL(QUERY_PROLOG, "SELECT ?s ?literal", "WHERE {", " (?s ?score ?literal) text:query ('text') .", "}");
Set<String> expectedURIs = new HashSet<>();
expectedURIs.addAll(Arrays.asList(R_S1));
Map<String, Literal> literals = doTestSearchWithLiterals(turtle, queryString, expectedURIs);
Literal value = literals.get(R_S1);
assertNotNull(value);
assertEquals(NodeFactory.createLiteral("text"), value.asNode());
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestDatasetWithLuceneStoredLiterals method testLiteralValueNonDefaultField.
@Test
public void testLiteralValueNonDefaultField() {
// test basic capturing of the literal value in a variable
final String testName = "testLiteralValueNonDefaultField";
final String turtle = StrUtils.strjoinNL(TURTLE_PROLOG, "<" + RESOURCE_BASE + testName + ">", " rdfs:comment 'a text comment'", ".");
String queryString = StrUtils.strjoinNL(QUERY_PROLOG, "SELECT ?s ?literal", "WHERE {", " (?s ?score ?literal) text:query (rdfs:comment 'text') .", "}");
Set<String> expectedURIs = new HashSet<>();
expectedURIs.addAll(Arrays.asList(RESOURCE_BASE + testName));
Map<String, Literal> literals = doTestSearchWithLiterals(turtle, queryString, expectedURIs);
Literal value = literals.get(RESOURCE_BASE + testName);
assertNotNull(value);
assertEquals(NodeFactory.createLiteral("a text comment"), value.asNode());
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class FusekiBuilder method buildDataAccessPoint.
/** Build a DataAccessPoint, including DataService at Resource svc */
public static DataAccessPoint buildDataAccessPoint(Resource svc, DatasetDescriptionRegistry dsDescMap) {
RDFNode n = FusekiLib.getOne(svc, "fu:name");
if (!n.isLiteral())
throw new FusekiConfigException("Not a literal for access point name: " + FmtUtils.stringForRDFNode(n));
Literal object = n.asLiteral();
if (object.getDatatype() != null && !object.getDatatype().equals(XSDDatatype.XSDstring))
Fuseki.configLog.error(format("Service name '%s' is not a string", FmtUtils.stringForRDFNode(object)));
String name = object.getLexicalForm();
name = DataAccessPoint.canonical(name);
DataService dataService = FusekiBuilder.buildDataService(svc, dsDescMap);
DataAccessPoint dataAccess = new DataAccessPoint(name, dataService);
return dataAccess;
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class RDFOutput method asRDF.
public Resource asRDF(Model model, ResultSet resultSet, boolean includeRowIndex) {
Resource results = model.createResource();
// This always goes in.
results.addProperty(RDF.type, ResultSetGraphVocab.ResultSet);
for (String vName : resultSet.getResultVars()) results.addProperty(ResultSetGraphVocab.resultVariable, vName);
int count = 0;
for (; resultSet.hasNext(); ) {
count++;
QuerySolution rBind = resultSet.nextSolution();
Resource thisSolution = model.createResource();
if (includeTypeProperties)
thisSolution.addProperty(RDF.type, ResultSetGraphVocab.ResultSolution);
results.addProperty(ResultSetGraphVocab.solution, thisSolution);
if (includeRowIndex) {
// This can lead to equivalent result sets having different graphs
// Best used if and only if query was completely sorted.
Literal x = model.createTypedLiteral(count + "", XSDDatatype.XSDinteger);
thisSolution.addLiteral(ResultSetGraphVocab.index, x);
}
Iterator<String> iter = getAllVars() ? rBind.varNames() : resultSet.getResultVars().iterator();
for (; iter.hasNext(); ) {
Resource thisBinding = model.createResource();
String rVar = iter.next();
RDFNode n = rBind.get(rVar);
if (n == null)
continue;
// }
if (includeTypeProperties)
thisBinding.addProperty(RDF.type, ResultSetGraphVocab.ResultBinding);
thisBinding.addProperty(ResultSetGraphVocab.variable, rVar);
thisBinding.addProperty(ResultSetGraphVocab.value, n);
thisSolution.addProperty(ResultSetGraphVocab.binding, thisBinding);
}
}
results.addProperty(ResultSetGraphVocab.size, model.createTypedLiteral(count));
addPrefixes(model);
return results;
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class AbstractContainerMethods method testFillingContainer.
public void testFillingContainer() {
final Container c = createContainer();
final String lang = "fr";
final Literal tvLiteral = model.createLiteral("test 12 string 2");
// Resource tvResObj = model.createResource( new ResTestObjF() );
c.add(AbstractModelTestBase.tvBoolean);
Assert.assertTrue(c.contains(AbstractModelTestBase.tvBoolean));
c.add(AbstractModelTestBase.tvByte);
Assert.assertTrue(c.contains(AbstractModelTestBase.tvByte));
c.add(AbstractModelTestBase.tvShort);
Assert.assertTrue(c.contains(AbstractModelTestBase.tvShort));
c.add(AbstractModelTestBase.tvInt);
Assert.assertTrue(c.contains(AbstractModelTestBase.tvInt));
c.add(AbstractModelTestBase.tvLong);
Assert.assertTrue(c.contains(AbstractModelTestBase.tvLong));
c.add(AbstractModelTestBase.tvChar);
Assert.assertTrue(c.contains(AbstractModelTestBase.tvChar));
c.add(AbstractModelTestBase.tvFloat);
Assert.assertTrue(c.contains(AbstractModelTestBase.tvFloat));
c.add(AbstractModelTestBase.tvString);
Assert.assertTrue(c.contains(AbstractModelTestBase.tvString));
c.add(AbstractModelTestBase.tvString, lang);
Assert.assertTrue(c.contains(AbstractModelTestBase.tvString, lang));
c.add(tvLiteral);
Assert.assertTrue(c.contains(tvLiteral));
// c.add( tvResObj ); assertTrue( c.contains( tvResObj ) );
c.add(AbstractModelTestBase.tvLitObj);
Assert.assertTrue(c.contains(AbstractModelTestBase.tvLitObj));
Assert.assertEquals(11, c.size());
}
Aggregations