Search in sources :

Example 56 with Model

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

the class TestLangTurtle method blankNodes2.

@Test
public void blankNodes2() {
    // Duplicate.
    String s = "_:a <http://example/p> 'foo' . _:a <http://example/p> 'foo' .";
    StringReader r = new StringReader(s);
    Model m = ModelFactory.createDefaultModel();
    RDFDataMgr.read(m, r, null, RDFLanguages.TURTLE);
    assertEquals(1, m.size());
}
Also used : StringReader(java.io.StringReader) Model(org.apache.jena.rdf.model.Model) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 57 with Model

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

the class TestLangTurtle method blankNodes1.

@Test
public void blankNodes1() {
    String s = "_:a <http://example/p> 'foo' . ";
    StringReader r = new StringReader(s);
    Model m = ModelFactory.createDefaultModel();
    RDFDataMgr.read(m, r, null, RDFLanguages.TURTLE);
    assertEquals(1, m.size());
    String x = m.listStatements().next().getSubject().getId().getLabelString();
    assertNotEquals(x, "a");
    // reset - reread - new bNode.
    r = new StringReader(s);
    RDFDataMgr.read(m, r, null, RDFLanguages.TURTLE);
    assertEquals(2, m.size());
}
Also used : StringReader(java.io.StringReader) Model(org.apache.jena.rdf.model.Model) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 58 with Model

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

the class TestLangTurtle method updatePrefixMapping2.

@Test
public void updatePrefixMapping2() {
    // Test that prefixes are resolved
    Model model = ModelFactory.createDefaultModel();
    StringReader reader = new StringReader("BASE <http://example/> PREFIX x: <abc>");
    RDFDataMgr.read(model, reader, null, RDFLanguages.TURTLE);
    assertEquals(1, model.getNsPrefixMap().size());
    assertEquals("http://example/abc", model.getNsPrefixURI("x"));
}
Also used : Model(org.apache.jena.rdf.model.Model) StringReader(java.io.StringReader) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 59 with Model

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

the class TestLangRdfJson method rdfjson_read_simple_plainliteral_object.

@Test
public void rdfjson_read_simple_plainliteral_object() {
    String s = "{ \"http://example.org/subject\" : { \"http://example.org/predicate\" : [ { \"type\" : \"literal\" , \"value\" : \"some text\" } ] } }";
    String s2 = "<http://example.org/subject> <http://example.org/predicate> \"some text\" .";
    assertEquals(1, parseCount(s));
    Model m = parseToModelRdfJson(s);
    Model m2 = parseToModelNTriples(s2);
    assertTrue(m.isIsomorphicWith(m2));
}
Also used : Model(org.apache.jena.rdf.model.Model) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 60 with Model

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

the class TestLangRdfJson method rdfjson_read_simple_typedliteral_object.

@Test
public void rdfjson_read_simple_typedliteral_object() {
    String s = "{ \"http://example.org/subject\" : { \"http://example.org/predicate\" : [ { \"type\" : \"literal\" , \"value\" : \"some text\", \"datatype\" : \"http://example.org/datatype\" } ] } }";
    String s2 = "<http://example.org/subject> <http://example.org/predicate> \"some text\"^^<http://example.org/datatype> .";
    assertEquals(1, parseCount(s));
    Model m = parseToModelRdfJson(s);
    Model m2 = parseToModelNTriples(s2);
    assertTrue(m.isIsomorphicWith(m2));
}
Also used : Model(org.apache.jena.rdf.model.Model) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

Model (org.apache.jena.rdf.model.Model)444 Test (org.junit.Test)177 BaseTest (org.apache.jena.atlas.junit.BaseTest)96 Resource (org.apache.jena.rdf.model.Resource)87 StringReader (java.io.StringReader)43 Dataset (org.apache.jena.query.Dataset)31 RDFReader (org.apache.jena.rdf.model.RDFReader)30 Property (org.apache.jena.rdf.model.Property)24 DatasetAccessor (org.apache.jena.query.DatasetAccessor)20 InfModel (org.apache.jena.rdf.model.InfModel)20 Node (org.apache.jena.graph.Node)19 Statement (org.apache.jena.rdf.model.Statement)18 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)15 Reader (java.io.Reader)14 JsonString (org.apache.jena.atlas.json.JsonString)14 AbstractFusekiTest (org.apache.jena.fuseki.AbstractFusekiTest)14 FusekiTest (org.apache.jena.fuseki.FusekiTest)14 Graph (org.apache.jena.graph.Graph)14 JenaException (org.apache.jena.shared.JenaException)14 Triple (org.apache.jena.graph.Triple)13