use of org.apache.jena.riot.thrift.wire.RDF_Term in project jena by apache.
the class TestThriftTerm method testTerm.
private RDF_Term testTerm(Node node, PrefixMap pmap, boolean asValue) {
RDF_Term rt = ThriftConvert.convert(node, pmap, asValue);
assertTrue(rt.isSet());
if (node == null) {
assertTrue(rt.isSetUndefined());
} else if (node.isURI()) {
assertTrue(rt.isSetIri() || rt.isSetPrefixName());
if (rt.isSetIri()) {
RDF_IRI iri = rt.getIri();
assertEquals(node.getURI(), iri.getIri());
}
if (rt.isSetPrefixName()) {
assertTrue(rt.getPrefixName().isSetPrefix());
assertTrue(rt.getPrefixName().isSetLocalName());
}
} else if (rt.isSetValDecimal() || rt.isSetValDouble() || rt.isSetValInteger()) {
// And not reversible.
return rt;
} else if (node.isLiteral()) {
assertTrue(rt.isSetLiteral());
RDF_Literal lit = rt.getLiteral();
assertTrue(lit.isSetLex());
assertEquals(node.getLiteralLexicalForm(), lit.getLex());
// RDF 1.1
if (JenaRuntime.isRDF11) {
if (Util.isSimpleString(node)) {
assertFalse(lit.isSetDatatype());
assertFalse(lit.isSetDtPrefix());
assertFalse(lit.isSetLangtag());
} else if (Util.isLangString(node)) {
assertFalse(lit.isSetDatatype());
assertFalse(lit.isSetDtPrefix());
assertTrue(lit.isSetLangtag());
} else {
// Regular typed literal.
assertTrue(lit.isSetDatatype() || lit.isSetDtPrefix());
assertFalse(lit.isSetLangtag());
}
} else {
// RDF 1.0
if (node.getLiteralDatatype() == null) {
if (Util.isLangString(node)) {
assertFalse(lit.isSetDatatype());
assertFalse(lit.isSetDtPrefix());
assertTrue(lit.isSetLangtag());
} else {
assertFalse(lit.isSetDatatype());
assertFalse(lit.isSetDtPrefix());
assertFalse(lit.isSetLangtag());
}
} else {
assertTrue(lit.isSetDatatype() || lit.isSetDtPrefix());
}
}
} else if (node.isBlank()) {
assertTrue(rt.isSetBnode());
RDF_BNode bnode = rt.getBnode();
assertEquals(node.getBlankNodeLabel(), bnode.getLabel());
} else if (node.isVariable()) {
assertTrue(rt.isSetVariable());
assertEquals(node.getName(), rt.getVariable().getName());
} else if (Node.ANY.equals(node)) {
assertTrue(rt.isSetAny());
} else
fail("Unknown node type");
// And reverse
Node n2 = ThriftConvert.convert(rt, pmap);
assertEquals(node, n2);
return rt;
}
use of org.apache.jena.riot.thrift.wire.RDF_Term in project jena by apache.
the class TestThriftTerm method term_literal_02.
@Test
public void term_literal_02() {
RDF_Term rt = testTerm("'foo'@en");
assertFalse(rt.getLiteral().isSetDatatype());
assertFalse(rt.getLiteral().isSetDtPrefix());
assertTrue(rt.getLiteral().isSetLangtag());
}
use of org.apache.jena.riot.thrift.wire.RDF_Term in project jena by apache.
the class TestThriftTerm method term_uri_04.
@Test
public void term_uri_04() {
RDF_Term rt = testTerm("rdf:type");
assertTrue(rt.isSetPrefixName());
assertEquals(rt.getPrefixName().prefix, "rdf");
assertEquals(rt.getPrefixName().localName, "type");
}
use of org.apache.jena.riot.thrift.wire.RDF_Term in project jena by apache.
the class TestThriftTerm method term_literal_05.
@Test
public void term_literal_05() {
RDF_Term rt = testTerm("'foo'^^<http://example/>");
assertFalse(rt.getLiteral().isSetDatatype());
assertTrue(rt.getLiteral().isSetDtPrefix());
assertEquals(rt.getLiteral().getDtPrefix().getPrefix(), "");
assertEquals(rt.getLiteral().getDtPrefix().getLocalName(), "");
}
use of org.apache.jena.riot.thrift.wire.RDF_Term in project jena by apache.
the class TestThriftTerm method term_uri_03.
@Test
public void term_uri_03() {
RDF_Term rt = testTerm("<http://namespace/ns#foobar>");
assertTrue(rt.isSetPrefixName());
assertEquals(rt.getPrefixName().prefix, "ns");
assertEquals(rt.getPrefixName().localName, "foobar");
}
Aggregations