Search in sources :

Example 81 with Resource

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\" : \"")));
}
Also used : Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) JsonString(org.apache.jena.atlas.json.JsonString) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 82 with Resource

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);
}
Also used : StringTokenizer(java.util.StringTokenizer) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 83 with Resource

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;
}
Also used : SpatialVocab.pDataset(org.apache.jena.query.spatial.assembler.SpatialVocab.pDataset) Dataset(org.apache.jena.query.Dataset) SpatialIndex(org.apache.jena.query.spatial.SpatialIndex) Resource(org.apache.jena.rdf.model.Resource)

Example 84 with Resource

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;
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) ARQException(org.apache.jena.sparql.ARQException) Literal(org.apache.jena.rdf.model.Literal) ArrayList(java.util.ArrayList) Resource(org.apache.jena.rdf.model.Resource) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 85 with Resource

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");
}
Also used : TestSuite(junit.framework.TestSuite) ARQTestSuite(org.apache.jena.sparql.ARQTestSuite) Node(org.apache.jena.graph.Node) Literal(org.apache.jena.rdf.model.Literal) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) EarlReport(org.apache.jena.sparql.junit.EarlReport)

Aggregations

Resource (org.apache.jena.rdf.model.Resource)179 Model (org.apache.jena.rdf.model.Model)87 Test (org.junit.Test)55 Property (org.apache.jena.rdf.model.Property)35 RDFNode (org.apache.jena.rdf.model.RDFNode)25 Dataset (org.apache.jena.query.Dataset)20 Literal (org.apache.jena.rdf.model.Literal)17 BaseTest (org.apache.jena.atlas.junit.BaseTest)16 Node (org.apache.jena.graph.Node)16 Statement (org.apache.jena.rdf.model.Statement)15 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)13 StringReader (java.io.StringReader)9 Triple (org.apache.jena.graph.Triple)9 InfModel (org.apache.jena.rdf.model.InfModel)9 Reader (java.io.Reader)8 ArrayList (java.util.ArrayList)8 JsonString (org.apache.jena.atlas.json.JsonString)8 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)6 PrefixMapping (org.apache.jena.shared.PrefixMapping)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5