Search in sources :

Example 11 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class DatasetFactory method assemble.

/**
	 * Assemble a dataset from the model
	 *
	 * @param model
	 * @return Dataset
	 */
public static Dataset assemble(Model model) {
    Objects.requireNonNull(model, "model can not be null");
    Resource r = GraphUtils.findRootByType(model, DatasetAssembler.getType());
    if (r == null)
        throw new ARQException("No root found for type <" + DatasetAssembler.getType() + ">");
    return assemble(r);
}
Also used : ARQException(org.apache.jena.sparql.ARQException) Resource(org.apache.jena.rdf.model.Resource)

Example 12 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class DescribeBNodeClosure method describe.

// Check all named graphs
@Override
public void describe(Resource r) {
    // Default model.
    Closure.closure(otherModel(r, dataset.getDefaultModel()), false, acc);
    // Find all the named graphs in which this resource
    // occurs as a subject.  Faster than iterating in the
    // names of graphs in the case of very large numbers
    // of graphs, few of which contain the resource, in
    // some kind of persistent storage.
    QuerySolutionMap qsm = new QuerySolutionMap();
    qsm.add("s", r);
    QueryExecution qExec = QueryExecutionFactory.create(query, dataset, qsm);
    ResultSet rs = qExec.execSelect();
    for (; rs.hasNext(); ) {
        QuerySolution qs = rs.next();
        String gName = qs.getResource("g").getURI();
        Model model = dataset.getNamedModel(gName);
        Resource r2 = otherModel(r, model);
        Closure.closure(r2, false, acc);
    }
    //        // Named graphs
    //        for ( Iterator<String> iter = dataset.listNames() ; iter.hasNext() ; )
    //        {
    //            String name = iter.next();
    //            Model model =  dataset.getNamedModel(name) ;
    //            Resource r2 = otherModel(r, model) ;
    //            Closure.closure(r2, false, acc) ;
    //        }
    Closure.closure(r, false, acc);
}
Also used : Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource)

Example 13 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestAssemblerGroup method testPassesSelfIn.

public void testPassesSelfIn() {
    final AssemblerGroup group = AssemblerGroup.create();
    final Object result = new Object();
    Assembler fake = new AssemblerBase() {

        @Override
        public Object open(Assembler a, Resource root, Mode irrelevant) {
            assertSame("nested call should pass in assembler group:", group, a);
            return result;
        }
    };
    group.implementWith(JA.Object, fake);
    assertSame(result, group.open(resourceInModel("x rdf:type ja:Object")));
}
Also used : Mode(org.apache.jena.assembler.Mode) Resource(org.apache.jena.rdf.model.Resource) ExpandingAssemblerGroup(org.apache.jena.assembler.assemblers.AssemblerGroup.ExpandingAssemblerGroup) AssemblerGroup(org.apache.jena.assembler.assemblers.AssemblerGroup) Assembler(org.apache.jena.assembler.Assembler) InfModelAssembler(org.apache.jena.assembler.assemblers.InfModelAssembler) AssemblerBase(org.apache.jena.assembler.assemblers.AssemblerBase)

Example 14 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestFileManagerAssembler method testCreatesFileManagerWIthHandlers.

/**
        Can't just test for equality of locators list, since locators don't support
        equality. Weak hack: check that the sizes are the same. TODO improve.
     */
public void testCreatesFileManagerWIthHandlers() {
    Resource root = resourceInModel("f rdf:type ja:FileManager");
    Assembler a = new FileManagerAssembler();
    FileManager f = (FileManager) a.open(null, root);
    List<Locator> wanted = IteratorCollection.iteratorToList(standardLocators());
    List<Locator> obtained = IteratorCollection.iteratorToList(f.locators());
    assertEquals(wanted.size(), obtained.size());
    assertEquals(wanted, obtained);
}
Also used : FileManagerAssembler(org.apache.jena.assembler.assemblers.FileManagerAssembler) Resource(org.apache.jena.rdf.model.Resource) FileManagerAssembler(org.apache.jena.assembler.assemblers.FileManagerAssembler)

Example 15 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestFileManagerAssembler method testCreatesFileManager.

public void testCreatesFileManager() {
    Resource root = resourceInModel("r rdf:type ja:FileManager");
    Assembler a = new FileManagerAssembler();
    Object x = a.open(root);
    assertInstanceOf(FileManager.class, x);
}
Also used : FileManagerAssembler(org.apache.jena.assembler.assemblers.FileManagerAssembler) Resource(org.apache.jena.rdf.model.Resource) FileManagerAssembler(org.apache.jena.assembler.assemblers.FileManagerAssembler)

Aggregations

Resource (org.apache.jena.rdf.model.Resource)178 Model (org.apache.jena.rdf.model.Model)86 Test (org.junit.Test)55 Property (org.apache.jena.rdf.model.Property)34 RDFNode (org.apache.jena.rdf.model.RDFNode)24 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)14 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)13 StringReader (java.io.StringReader)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 Triple (org.apache.jena.graph.Triple)8 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)6 PrefixMapping (org.apache.jena.shared.PrefixMapping)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5