use of org.apache.jena.riot.thrift.wire.RDF_IRI 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;
}
Aggregations