本文整理汇总了Java中org.apache.jena.datatypes.RDFDatatype类的典型用法代码示例。如果您正苦于以下问题:Java RDFDatatype类的具体用法?Java RDFDatatype怎么用?Java RDFDatatype使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RDFDatatype类属于org.apache.jena.datatypes包,在下文中一共展示了RDFDatatype类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromThrift
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
public static Node fromThrift(RDF_Term term) {
if ( term.isSetIri() )
return NodeFactory.createURI(term.getIri().getIri()) ;
if ( term.isSetBnode() )
return NodeFactory.createBlankNode(term.getBnode().getLabel()) ;
if ( term.isSetLiteral() ) {
RDF_Literal lit = term.getLiteral() ;
String lex = lit.getLex() ;
String dtString = null ;
if ( lit.isSetDatatype() )
dtString = lit.getDatatype() ;
RDFDatatype dt = NodeFactory.getType(dtString) ;
String lang = lit.getLangtag() ;
return NodeFactory.createLiteral(lex, lang, dt) ;
}
throw new PatchException("No conversion to a Node: "+term.toString()) ;
}
示例2: exec
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
@Override
protected NodeValue exec(Node literalNode, Node datatypeNode, FunctionEnv env) {
if(literalNode == null || !literalNode.isLiteral()) {
throw new ExprEvalException();
}
String lex = literalNode.getLiteralLexicalForm();
if(!datatypeNode.isURI()) {
throw new ExprEvalException();
}
RDFDatatype datatype = TypeMapper.getInstance().getTypeByName(datatypeNode.getURI());
if(datatype == null) {
return NodeValue.TRUE;
}
else {
boolean valid = datatype.isValid(lex);
return NodeValue.makeBoolean(valid);
}
}
示例3: createTyped
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
public static final RDFNode createTyped(String value, Resource valueType)
{
if (value == null) throw new IllegalArgumentException("Param value cannot be null");
// without value type, return default xsd:string value
if (valueType == null) return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDstring);
// if value type is from XSD namespace, value is treated as typed literal with XSD datatype
if (valueType.getNameSpace().equals(XSD.getURI()))
{
RDFDatatype dataType = NodeFactory.getType(valueType.getURI());
return ResourceFactory.createTypedLiteral(value, dataType);
}
// otherwise, value is treated as URI resource
else
return ResourceFactory.createResource(value);
}
示例4: createNode
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
private Node createNode(Map<String, Object> map) {
String type = (String)map.get("type") ;
String lex = (String)map.get("value") ;
if ( type.equals(IRI) )
return NodeFactory.createURI(lex);
else if ( type.equals(BLANK_NODE) )
return labels.get(null, lex) ; //??
else if ( type.equals(LITERAL) ) {
String lang = (String)map.get("language") ;
String datatype = (String)map.get("datatype") ;
if ( Objects.equals(xsdString, datatype) )
// In RDF 1.1, simple literals and xsd:string are the same.
// During migration, we prefer simple literals to xsd:strings.
datatype = null ;
if ( lang == null && datatype == null )
return NodeFactory.createLiteral(lex);
if ( lang != null )
return NodeFactory.createLiteral(lex, lang);
RDFDatatype dt = NodeFactory.getType(datatype) ;
return NodeFactory.createLiteral(lex, dt);
} else
throw new InternalErrorException("Node is not a IRI, bNode or a literal: " + type) ;
}
示例5: convert
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
/**
* Convert the literal into natural language.
*
* @param lit
* the literal
* @return the natural language expression
*/
public String convert(LiteralLabel lit) {
logger.debug("Literal to be converted" + lit.toString());
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
if (dt == null || dt instanceof RDFLangString) {// plain literal, i.e.
// omit language tag if
// exists
s = lit.getLexicalForm();
s = s.replaceAll("_", " ");
s = s.replace('*', ' ');
s = s.trim();
if (encapsulateStringLiterals) {
s = '"' + s + '"';
}
} else {// typed literal
if (dt instanceof XSDDatatype) {// built-in XSD datatype
if (dt instanceof XSDAbstractDateTimeType) {// date datetypes
s = convertDateLiteral(lit);
} else if (encapsulateStringLiterals && dt.equals(XSDDatatype.XSDstring)) {
s = s.replace('*', ' ');
s = s.trim();
s = '"' + s + '"';
}
} else {// user-defined datatype
String text = iriConverter.convert(dt.getURI(), false).toLowerCase();
String[] split = StringUtils.splitByCharacterTypeCamelCase(text.trim());
String datatype = Joiner.on(" ").join(Arrays.asList(split).stream().filter(str -> !str.trim().isEmpty())
.collect(Collectors.toList()));
s = lit.getLexicalForm() + " " + datatype;
}
}
return s;
}
示例6: convert
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
/**
* Convert the literal into natural language.
* @param lit the literal
* @return the natural language expression
*/
public String convert(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
if (dt == null || dt instanceof RDFLangString) {// plain literal, i.e. omit language tag if exists
s = lit.getLexicalForm();
s = s.replaceAll("_", " ");
if(encapsulateStringLiterals){
s = '"' + s + '"';
}
} else {// typed literal
if (dt instanceof XSDDatatype) {// built-in XSD datatype
if(dt instanceof XSDAbstractDateTimeType){//date datetypes
s = convertDateLiteral(lit);
} else if(encapsulateStringLiterals && dt.equals(XSDDatatype.XSDstring)){
s = '"' + s + '"';
}
} else {// user-defined datatype
String text = iriConverter.convert(dt.getURI(), false).toLowerCase();
String[] split = StringUtils.splitByCharacterTypeCamelCase(text.trim());
String datatype = Joiner.on(" ").join(Arrays.asList(split).stream().filter(str -> !str.trim().isEmpty()).collect(Collectors.toList()));
s = lit.getLexicalForm() + " " + datatype;
}
}
return s;
}
示例7: convert
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
/**
* Convert the literal into natural language.
*
* @param lit
* the literal
* @return the natural language expression
*/
public String convert(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
if (dt == null || dt instanceof RDFLangString) {// plain literal, i.e.
// omit language tag if
// exists
s = lit.getLexicalForm();
s = s.replaceAll("_", " ");
if (encapsulateStringLiterals) {
s = '"' + s + '"';
}
} else {// typed literal
if (dt instanceof XSDDatatype) {// built-in XSD datatype
if (dt instanceof XSDAbstractDateTimeType) {// date datetypes
s = convertDateLiteral(lit);
} else if (encapsulateStringLiterals && dt.equals(XSDDatatype.XSDstring)) {
s = '"' + s + '"';
}
} else {// user-defined datatype
String text = iriConverter.convert(dt.getURI(), false).toLowerCase();
String[] split = StringUtils.splitByCharacterTypeCamelCase(text.trim());
String datatype = Joiner.on(" ").join(Arrays.asList(split).stream().filter(str -> !str.trim().isEmpty())
.collect(Collectors.toList()));
s = lit.getLexicalForm() + " " + datatype;
}
}
return s;
}
示例8: build
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
public org.apache.jena.graph.Node build() {
if (dt != null) {
RDFDatatype dType = TypeMapper.getInstance().getSafeTypeByName(dt);
return NodeFactory.createLiteral(value, dType);
} else if (lang != null && !lang.isEmpty())
return NodeFactory.createLiteral(value, lang);
else
return NodeFactory.createLiteral(value);
}
示例9: exec
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
@Override
public List<NodeValue> exec(NodeValue cbor, NodeValue jsonpath) {
if (cbor.getDatatypeURI() != null
&& !cbor.getDatatypeURI().equals(datatypeUri)
&& !cbor.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
LOG.warn("The URI of NodeValue1 MUST be"
+ " <" + datatypeUri + "> or"
+ " <http://www.w3.org/2001/XMLSchema#string>. Got <"
+ cbor.getDatatypeURI() + ">. Returning null.");
}
Configuration conf = Configuration.builder()
.options(Option.ALWAYS_RETURN_LIST).build();
String json = new String(Base64.getDecoder().decode(cbor.asNode().getLiteralLexicalForm().getBytes()));
try {
List<Object> values = JsonPath
.using(conf)
.parse(json)
.read(jsonpath.getString());
List<NodeValue> nodeValues = new ArrayList<>(values.size());
Gson gson = new Gson();
for (Object value : values) {
RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(datatypeUri);
String jsonstring = gson.toJson(value);
Node node = NodeFactory.createLiteral(jsonstring, dt);
NodeValue nodeValue = new NodeValueNode(node);
nodeValues.add(nodeValue);
}
return nodeValues;
} catch (Exception ex) {
LOG.debug("No evaluation of " + cbor + ", " + jsonpath, ex);
throw new ExprEvalException("No evaluation of " + cbor + ", " + jsonpath, ex);
}
}
示例10: exec
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
@Override
public List<NodeValue> exec(NodeValue json, NodeValue jsonquery) {
if (json.getDatatypeURI() != null
&& !json.getDatatypeURI().equals(datatypeUri)
&& !json.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
LOG.warn("The URI of NodeValue1 MUST be"
+ " <" + datatypeUri + "> or"
+ " <http://www.w3.org/2001/XMLSchema#string>. Got "
+ json.getDatatypeURI());
}
Configuration conf = Configuration.builder()
.options(Option.ALWAYS_RETURN_LIST).build();
try {
List<Object> values = JsonPath
.using(conf)
.parse(json.asNode().getLiteralLexicalForm())
.read(jsonquery.getString());
List<NodeValue> nodeValues = new ArrayList<>(values.size());
Gson gson = new Gson();
for (Object value : values) {
RDFDatatype dt = TypeMapper.getInstance().getSafeTypeByName(datatypeUri);
String jsonstring = gson.toJson(value);
Node node = NodeFactory.createLiteral(jsonstring, dt);
NodeValue nodeValue = new NodeValueNode(node);
nodeValues.add(nodeValue);
}
return nodeValues;
} catch (Exception ex) {
LOG.debug("No evaluation for " + json + ", " + jsonquery, ex);
throw new ExprEvalException("No evaluation for " + json + ", " + jsonquery, ex);
}
}
示例11: exec
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
@Override
public List<NodeValue> exec(NodeValue html, NodeValue cssSelector) {
if (html.getDatatypeURI() != null
&& !html.getDatatypeURI().equals(datatypeUri)
&& !html.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
LOG.warn("The URI of NodeValue1 MUST be"
+ " <" + datatypeUri + "> or"
+ " <http://www.w3.org/2001/XMLSchema#string>. Got <"
+ html.getDatatypeURI() + ">. Returning null.");
}
RDFDatatype dt = TypeMapper.getInstance()
.getSafeTypeByName(datatypeUri);
try {
String sourceHtml = String.valueOf(html.asNode().getLiteralLexicalForm());
Document htmldoc = Jsoup.parse(sourceHtml);
String selectPath = String.valueOf(cssSelector.asNode().getLiteralValue());
Elements elements = htmldoc.select(selectPath);
LOG.debug("===> Number of iterations for " + cssSelector + " " + elements.size());
List<NodeValue> nodeValues = new ArrayList<>(elements.size());
NodeValue nodeValue;
for (Element element : elements) {
String htmlValue = element.toString();
Node node = NodeFactory.createLiteral(htmlValue, dt);
nodeValue = new NodeValueNode(node);
nodeValues.add(nodeValue);
}
return nodeValues;
} catch (Exception ex) {
LOG.debug("No evaluation of " + html + ", " + cssSelector, ex);
throw new ExprEvalException("No evaluation of " + html + ", " + cssSelector, ex);
}
}
示例12: getNode
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public static Node getNode(Object obj) {
if(obj == null) {
return null;
}
else if(obj instanceof JSTerm) {
return ((JSTerm)obj).getNode();
}
else if(obj instanceof Map) {
Map som = (Map) obj;
String value = (String) som.get(VALUE);
if(value == null) {
throw new IllegalArgumentException("Missing value");
}
String termType = (String) som.get(TERM_TYPE);
if(NAMED_NODE.equals(termType)) {
return NodeFactory.createURI(value);
}
else if(BLANK_NODE.equals(termType)) {
return NodeFactory.createBlankNode(value);
}
else if(LITERAL.equals(termType)) {
String lang = (String) som.get(LANGUAGE);
Map dt = (Map)som.get(DATATYPE);
String dtURI = (String)dt.get(VALUE);
RDFDatatype datatype = TypeMapper.getInstance().getSafeTypeByName(dtURI);
return NodeFactory.createLiteral(value, lang, datatype);
}
else {
throw new IllegalArgumentException("Unsupported term type " + termType);
}
}
else {
return null;
}
}
示例13: bodyCall
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
public boolean bodyCall(Node[] args, int length, RuleContext context) {
BindingEnvironment env = context.getEnv();
Node value = env.getGroundVersion(args[0]);
TypeMapper tm = TypeMapper.getInstance();
RDFDatatype type = tm.getTypeByName(PrintUtil.expandQname(args[2].toString()));
Node cast = NodeFactory.createLiteral(value.getLiteral().getValue().toString(),null,type);
env.bind(args[1],cast);
return type.isValid(value.getLiteral().getValue().toString());
}
示例14: bodyCall
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
public boolean bodyCall(Node[] args, int length, RuleContext context) {
BindingEnvironment env = context.getEnv();
InfGraph graph = context.getGraph();
Node s = env.getGroundVersion(args[0]);
Node p = env.getGroundVersion(args[1]);
ExtendedIterator i = graph.find(s,p,null);
int n = i.toSet().size();
TypeMapper tm = TypeMapper.getInstance();
RDFDatatype type = tm.getTypeByName(XSD.xint.getURI());
Node count = NodeFactory.createLiteral(Integer.toString(n),null,type);
env.bind(args[2],count);
return true;
}
示例15: toRDFList
import org.apache.jena.datatypes.RDFDatatype; //导入依赖的package包/类
/** incrementally add a value to an RDFList */
public static RDFList toRDFList(Node node, String value, String itemType, RDFList list, Set<restriction> restrictions, Context ctx)
throws Exception {
RDFDatatype dt = getDatatype(itemType);
Model m = ctx.getModel();
RDFNode object = null;
value = processWhitespace(node,value,itemType,ctx);
if (itemType!=null && itemType.equals(XSD_URI+"#QName")) {
String name = expandQName(ctx.getDefaultNS(),null,value,node,ctx.getModel());
if (name==null) return null; // one bad value invalidates the entire list
else object = m.createResource(name);
}
else if (itemType!=null && itemType.equals(XSD.IDREF.getURI())) {
if (value.indexOf(':')>=0) return null; // avoid confusion with QNames
object = ctx.getModel().createResource(addFragment(ctx.getBaseMap(), value).toString());
}
else if (itemType!=null && itemType.equals(XSD_URI+"#anyURI")) {
URI uri = null;
if (isValidURI(value)) uri = new URI(value);
// ensure this isn't a QName
else if (value.indexOf(":")<0 && Character.isJavaIdentifierStart(value.charAt(0)))
uri = resolveBase(node, new URI(value), ctx);
if (uri!=null) object = m.createTypedLiteral(uri.toString(),dt);
else return null;
}
else if (value!=null && dt!=null && dt.isValid(value)) object = m.createTypedLiteral(value, dt);
else object = m.createLiteral(value==null?"":value);
// add the value to the list
if (list.isEmpty()) list = ctx.getModel().createList(new RDFNode[] {object});
else list.add(object);
return list;
}