use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class TestJsonLDWriter method clashOfPropLocalnames.
/**
* Check there are no problems when 2 properties have the same localname
*/
@Test
public final void clashOfPropLocalnames() {
Model m = ModelFactory.createDefaultModel();
Resource s = m.createResource();
String ns1 = "http://schema.org/";
String ns2 = "http://ex.com/";
m.add(s, m.createProperty(ns1 + "name"), "schema.org name");
m.add(s, m.createProperty(ns2 + "name"), "ex.com name");
String jsonld = toString(m, RDFFormat.JSONLD, null);
// in one case, we have "name" : "xxx", and the other "http://.../name" : "yyy"
assertTrue(jsonld.contains("\"name\" : \""));
assertTrue(jsonld.contains("/name\" : \""));
m.setNsPrefix("ns1", ns1);
m.setNsPrefix("ns2", "http://ex.com/");
jsonld = toString(m, RDFFormat.JSONLD, null);
// we get either:
/*
"name" : "ex.com name",
"ns1:name" : "schema.org name",
*/
// or
/*
"name" : "schema.org name",
"ns2:name" : "ex.com name",
*/
assertTrue(jsonld.contains("\"name\" : \""));
assertTrue((jsonld.contains("\"ns1:name\" : \"")) || (jsonld.contains("\"ns2:name\" : \"")));
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class ModelHelper method statement.
public static Statement statement(String fact) {
StringTokenizer st = new StringTokenizer(fact);
Resource sub = resource(st.nextToken());
Property pred = property(st.nextToken());
RDFNode obj = rdfNode(st.nextToken());
return builderModel.createStatement(sub, pred, obj);
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class SpatialDatasetAssembler method open.
// private DatasetAssembler datasetAssembler = new DatasetAssembler() ;
//
// public static Resource getType() { return textDataset ; }
/*
<#spatial_dataset> rdf:type spatial:SpatialDataset ;
spatial:dataset <#dataset> ;
spatial:index <#index> ;
.
*/
@Override
public Dataset open(Assembler a, Resource root, Mode mode) {
Resource dataset = GraphUtils.getResourceValue(root, pDataset);
Resource index = GraphUtils.getResourceValue(root, pIndex);
Dataset ds = (Dataset) a.open(dataset);
SpatialIndex textIndex = (SpatialIndex) a.open(index);
Dataset dst = SpatialDatasetFactory.create(ds, textIndex);
return dst;
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class ResultSetUtils method resultSetToStringList.
/**
* Extracts a List filled with the binding of selectElement variable for each
* query solution, turned into a string (URIs or lexical forms).
* Exhausts the result set. Create a rewindable one to use multiple times.
* @see org.apache.jena.query.ResultSetFactory
*/
public static List<String> resultSetToStringList(ResultSet rs, String selectElement, String literalOrResource) {
// feature suggested by James Howison
List<String> items = new ArrayList<>();
while (rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
RDFNode rn = qs.get(selectElement);
if (rn.isLiteral())
items.add(((Literal) rn).getLexicalForm());
else if (rn.isURIResource())
items.add(((Resource) rn).getURI());
else if (rn.isAnon()) {
items.add(((Resource) rn).getId().getLabelString());
} else
throw new ARQException("Unknow thing in results : " + rn);
}
return items;
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class qtest method oneManifestEarl.
static void oneManifestEarl(String testManifest) {
String name = "ARQ";
String releaseName = "ARQ";
String version = "2.9.1";
String homepage = "http://jena.apache.org/";
// Null for bNode.
String systemURI = "http://jena.apache.org/#arq";
// Include information later.
EarlReport report = new EarlReport(systemURI, name, version, homepage);
ScriptTestSuiteFactory.results = report;
Model model = report.getModel();
model.setNsPrefix("dawg", TestManifest.getURI());
// Update the EARL report.
Resource jena = model.createResource().addProperty(FOAF.homepage, model.createResource("http://jena.apache.org/"));
// ARQ is part fo Jena.
Resource arq = report.getSystem().addProperty(DCTerms.isPartOf, jena);
// Andy wrote the test software (updates the thing being tested as well as they are the same).
Resource who = model.createResource(FOAF.Person).addProperty(FOAF.name, "Andy Seaborne").addProperty(FOAF.homepage, model.createResource("http://people.apache.org/~andy"));
Resource reporter = report.getReporter();
reporter.addProperty(DC.creator, who);
model.setNsPrefix("doap", DOAP.getURI());
model.setNsPrefix("xsd", XSD.getURI());
// DAWG specific stuff.
Resource system = report.getSystem();
system.addProperty(RDF.type, DOAP.Project);
system.addProperty(DOAP.name, name);
system.addProperty(DOAP.homepage, homepage);
system.addProperty(DOAP.maintainer, who);
Resource release = model.createResource(DOAP.Version);
system.addProperty(DOAP.release, release);
Node today_node = NodeFactoryExtra.todayAsDate();
Literal today = model.createTypedLiteral(today_node.getLiteralLexicalForm(), today_node.getLiteralDatatype());
release.addProperty(DOAP.created, today);
// Again
release.addProperty(DOAP.name, releaseName);
TestSuite suite = ScriptTestSuiteFactory.make(testManifest);
SimpleTestRunner.runSilent(suite);
ScriptTestSuiteFactory.results.getModel().write(System.out, "TTL");
}
Aggregations