Search in sources :

Example 51 with Resource

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

the class TestTextIndexLuceneAssembler method testLiteralDirectory.

@Test
public void testLiteralDirectory() {
    TextIndexLuceneAssembler assembler = new TextIndexLuceneAssembler();
    Resource root = SIMPLE_INDEX_SPEC_LITERAL_DIR;
    Assembler a = Assembler.general;
    // the open method is not supposed to throw exceptions when the directory is
    // a literal
    TextIndexLucene index = (TextIndexLucene) assembler.open(a, root, /*mode*/
    null);
    try {
        assertNotNull(index);
    } finally {
        index.close();
    }
}
Also used : Resource(org.apache.jena.rdf.model.Resource) Assembler(org.apache.jena.assembler.Assembler) TextIndexLucene(org.apache.jena.query.text.TextIndexLucene) Test(org.junit.Test)

Example 52 with Resource

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

the class TestTextIndexLuceneAssembler method testMemDirectory.

@Test
public void testMemDirectory() {
    TextIndexLuceneAssembler assembler = new TextIndexLuceneAssembler();
    Resource root = SIMPLE_INDEX_SPEC_MEM_DIR;
    Assembler a = Assembler.general;
    // the open method is not supposed to throw exceptions when the directory is
    // a iri resource
    TextIndexLucene index = (TextIndexLucene) assembler.open(a, root, /*mode*/
    null);
    try {
        assertTrue(index.getDirectory() instanceof RAMDirectory);
    } finally {
        index.close();
    }
}
Also used : Resource(org.apache.jena.rdf.model.Resource) Assembler(org.apache.jena.assembler.Assembler) TextIndexLucene(org.apache.jena.query.text.TextIndexLucene) RAMDirectory(org.apache.lucene.store.RAMDirectory) Test(org.junit.Test)

Example 53 with Resource

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

the class TestInMemDatasetAssembler method directDataLinkForDefaultAndNamedGraphs.

@Test
public void directDataLinkForDefaultAndNamedGraphs() throws IOException {
    // first make a file of triples to load later
    final Model model = createDefaultModel();
    final Path triples = createTempFile("simpleExample", ".nt");
    final Resource triplesURI = model.createResource(triples.toFile().toURI().toString());
    final Resource simpleExample = model.createResource("test:simpleExample");
    simpleExample.addProperty(type, DatasetAssemblerVocab.tDatasetTxnMem);
    // add a default graph
    simpleExample.addProperty(data, triplesURI);
    // add a named graph
    final Resource namedGraphDef = model.createResource("test:namedGraphDef");
    simpleExample.addProperty(pNamedGraph, namedGraphDef);
    final Resource namedGraphName = model.createResource("test:namedGraphExample");
    namedGraphDef.addProperty(type, MemoryModel);
    namedGraphDef.addProperty(pGraphName, namedGraphName);
    namedGraphDef.addProperty(data, triplesURI);
    try (OutputStream out = new FileOutputStream(triples.toFile())) {
        write(out, model, NTRIPLES);
    }
    final Dataset dataset = assemble(simpleExample);
    final Model assembledDefaultModel = dataset.getDefaultModel();
    final Model assembledNamedModel = dataset.getNamedModel(namedGraphName.getURI());
    // we put the same triples in each model, so we check for the same triples in each model
    for (final Model m : new Model[] { assembledDefaultModel, assembledNamedModel }) {
        assertTrue(m.contains(simpleExample, pNamedGraph, namedGraphDef));
        assertTrue(m.contains(namedGraphDef, pGraphName, namedGraphName));
        assertTrue(m.contains(simpleExample, data, triplesURI));
    }
    final Iterator<Node> graphNodes = dataset.asDatasetGraph().listGraphNodes();
    assertTrue(graphNodes.hasNext());
    assertEquals(namedGraphName.asNode(), graphNodes.next());
    assertFalse(graphNodes.hasNext());
}
Also used : Path(java.nio.file.Path) Dataset(org.apache.jena.query.Dataset) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) MemoryModel(org.apache.jena.assembler.JA.MemoryModel) ModelFactory.createDefaultModel(org.apache.jena.rdf.model.ModelFactory.createDefaultModel) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test)

Example 54 with Resource

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

the class TestInMemDatasetAssembler method wrongKindOfAssemblerDefinition.

@Test(expected = CannotConstructException.class)
public void wrongKindOfAssemblerDefinition() {
    final Model model = createDefaultModel();
    final Resource badExample = model.createResource("test:badExample");
    assemble(badExample);
}
Also used : Model(org.apache.jena.rdf.model.Model) MemoryModel(org.apache.jena.assembler.JA.MemoryModel) ModelFactory.createDefaultModel(org.apache.jena.rdf.model.ModelFactory.createDefaultModel) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test)

Example 55 with Resource

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

the class rdflangtest method insertMetaOld.

//OLD meta.
static void insertMetaOld(EarlReport report) {
    Model model = report.getModel();
    /*
        <> foaf:primaryTopic <http://jena.apache.org/#riot> ;
            dc:issued "..."^^xsd:dateTime;
            foaf:maker who.
        */
    // Update the EARL report. 
    Resource jena = model.createResource().addProperty(FOAF.homepage, model.createResource("http://jena.apache.org/"));
    // ARQ is part of 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);
    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);
}
Also used : 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)

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