本文整理汇总了Java中com.hp.hpl.jena.rdf.model.Literal.getDatatypeURI方法的典型用法代码示例。如果您正苦于以下问题:Java Literal.getDatatypeURI方法的具体用法?Java Literal.getDatatypeURI怎么用?Java Literal.getDatatypeURI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.rdf.model.Literal
的用法示例。
在下文中一共展示了Literal.getDatatypeURI方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: asSesameLiteral
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
/**
* Convert the given Jena Literal to a Sesame Literal
* @param theLiteral the Jena Literal to convert
* @return the Jena Literal as a Sesame Literal
*/
public static org.openrdf.model.Literal asSesameLiteral(Literal theLiteral) {
if (theLiteral == null) {
return null;
}
else if (theLiteral.getLanguage() != null && !theLiteral.getLanguage().equals("")) {
return FACTORY.createLiteral(theLiteral.getLexicalForm(),
theLiteral.getLanguage());
}
else if (theLiteral.getDatatypeURI() != null) {
return FACTORY.createLiteral(theLiteral.getLexicalForm(),
FACTORY.createURI(theLiteral.getDatatypeURI()));
}
else {
return FACTORY.createLiteral(theLiteral.getLexicalForm());
}
}
示例2: writeStatement
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
private void writeStatement(Statement stmt, PrintStream out)
{
String name = getQName(stmt.getPredicate());
Map<String,String> attrs = null;
String value = null;
RDFNode node = stmt.getObject();
if ( node.isLiteral() )
{
Literal l = node.asLiteral();
value = l.getString();
String lang = l.getLanguage();
if ( !lang.isEmpty() ) { attrs = Collections.singletonMap("xml:lang", lang); }
String datatype = l.getDatatypeURI();
if ( datatype != null ) { attrs = Collections.singletonMap("rdf:datatype", datatype); }
}
else {
attrs = Collections.singletonMap("rdf:resource", getURI(node.asResource()));
}
writeProperty(name, attrs, value, out);
}
示例3: literal
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
private void literal(Literal l) {
atts.clear();
try {
String s = l.getLexicalForm();
String lang = l.getLanguage();
String dt = l.getDatatypeURI();
// Literal with lang?
if (lang != null && lang.length() != 0) {
atts.addAttribute(ARQConstants.XML_NS, "lang", "xml:lang", "CDATA", lang);
}
// Literal with datatype?
if (dt != null && dt.length() != 0) {
atts.addAttribute(dfNamespace, dfAttrDatatype, dfAttrDatatype, "CDATA", dt);
}
handler.startElement(dfNamespace, dfLiteral, dfLiteral, atts);
handler.characters(s.toCharArray(), 0, s.length());
handler.endElement(dfNamespace, dfLiteral, dfLiteral);
} catch (SAXException ex) {
}
}
示例4: checkDataPropertyValueInRange
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
public boolean checkDataPropertyValueInRange(OntModel theJenaModel2, Resource subj, OntProperty prop, Literal val) {
OntResource rng = prop.getRange();
if (rng == null) {
return true;
}
String ptype = prop.getRange().getURI();
if (ptype == null) {
return true;
}
String dtype = val.getDatatypeURI();
if (dtype.equals(ptype)) {
return true;
}
if (dtype.equals(XSD.xint.getURI())) { // the literal is an integer
if (ptype.equals(XSD.integer.getURI())) return true;
if (ptype.equals(XSD.xlong.getURI())) return true;
}
return false;
}
示例5: writeLiteral
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
protected void writeLiteral( Literal l, PrintWriter writer ) {
String lang = l.getLanguage();
String form = l.getLexicalForm();
if (!lang.equals("")) {
writer.print(" xml:lang=" + attributeQuoted( lang ));
}
if (l.isWellFormedXML() && !blockLiterals) {
writer.print(" " + rdfAt("parseType") + "=" + attributeQuoted( "Literal" )+">");
writer.print( form );
} else {
String dt = l.getDatatypeURI();
if (dt != null) writer.print( " " + rdfAt( "datatype" ) + "=" + substitutedAttribute( dt ) );
writer.print(">");
writer.print( Util.substituteEntitiesInElementContent( form ) );
}
}
示例6: asSesameLiteral
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
/**
* Convert the given Jena Literal to a Sesame Literal
* @param theLiteral the Jena Literal to convert
* @return the Jena Literal as a Sesame Literal
*/
public static org.openrdf.model.Literal asSesameLiteral(Literal theLiteral) {
if (theLiteral == null) {
return null;
}
else if (theLiteral.getLanguage() != null && !theLiteral.getLanguage().equals("")) {
return FACTORY.createLiteral(theLiteral.getLexicalForm(),
theLiteral.getLanguage());
}
else if (theLiteral.getDatatypeURI() != null) {
return FACTORY.createLiteral(theLiteral.getLexicalForm(),
FACTORY.createURI(theLiteral.getDatatypeURI()));
}
else {
return FACTORY.createLiteral(theLiteral.getLexicalForm());
}
}
示例7: object
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
private String object(RDFNode node) {
if (node.isLiteral()) {
Literal lit = node.asLiteral();
String text = lit.getString();
String lang = lit.getLanguage();
String type = lit.getDatatypeURI();
if (lang == null || "".equals(lang)) {
lang = "";
} else {
lang = " xml:lang='" + escapeXml(lang) + "'";
}
if ("".equals(lang)) {
if (type == null) {
type = "http://www.w3.org/2001/XMLSchema#string";
}
type = " datatype='" + escapeXml(type) + "'";
} else {
type = "";
}
return "<sem:object" + type + lang + ">" + escapeXml(text) + "</sem:object>";
} else if (node.isAnon()) {
return "<sem:object>http://marklogic.com/semantics/blank/" + Long.toHexString(
fuse(scramble((long)node.hashCode()),fuse(scramble(milliSecs),randomValue)))
+"</sem:object>";
} else {
return "<sem:object>" + escapeXml(node.toString()) + "</sem:object>";
}
}
示例8: apply
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
@Override
public Optional<String> apply(final Statement input) {
final RDFNode object=input.getObject();
if(object.isLiteral()) {
final Literal literal=object.asLiteral();
if(literal.getDatatypeURI()==null || "http://www.w3.org/2001/XMLSchema#string".equals(literal.getDatatypeURI())) {
return Optional.of(literal.getLexicalForm());
}
}
this.report.warn("Discarding invalid value for property %s: not a String Literal (%s)",input.getPredicate().getURI(),object);
return Optional.absent();
}
示例9: literalValueCompatibleWithRange
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
private boolean literalValueCompatibleWithRange(OntResource ror, Literal val) {
String dturi = val.getDatatypeURI();
if (ror.getURI().equals(dturi)) {
return true;
}
else if (ror.getURI().equals(XSD.xfloat.getURI()) && dturi.equals(XSD.xdouble.getURI())) {
return true;
}
else if (ror.getURI().equals(XSD.xdouble.getURI()) && dturi.equals(XSD.xfloat.getURI())) {
return true;
}
return false;
}
示例10: processProperty
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
private void processProperty(Statement property) throws IOException {
write("{ \"value\" : \"");
if (property.getObject().isURIResource()) {
Resource r = (Resource) property.getObject();
write(escape(r.getURI()));
write("\", \"type\" : \"uri\"");
} else if (property.getObject().isLiteral()) {
Literal l = (Literal) property.getObject();
write(escape(l.getLexicalForm()));
write("\", \"type\" : \"literal\"");
String languageValue = l.getLanguage();
if (languageValue != null && !languageValue.trim().equals("")) {
write(", \"lang\" : \"");
write(languageValue);
write("\"");
}
String dataTypeValue = l.getDatatypeURI();
if (dataTypeValue != null && !dataTypeValue.trim().equals("")) {
write(", \"datatype\" : \"");
write(escape(dataTypeValue));
write("\"");
}
} else if (property.getObject().isAnon()) {
write("_:");
write(escape(property.getObject().asNode().getBlankNodeId()
.getLabelString()));
write("\", \"type\" : \"bnode\"");
}
write(" }");
}
示例11: literalToSparqlSyntax
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
/**
* Formats a literal to a SPARQL-compatible string.
* @param lit a literal to be formatted
* @return a string representing the literal with SPARQL syntax.
* @see #parseLiteral(String, ModelCom)
*/
public static String literalToSparqlSyntax(Literal lit)
{
RDFDatatype litClass = lit.getDatatype();
if (litClass == XSDDatatype.XSDboolean || litClass == XSDDatatype.XSDint || litClass == XSDDatatype.XSDdouble)
{
return lit.getLexicalForm();
}
else return "'" + lit.getLexicalForm() + "'^^<" + lit.getDatatypeURI() + ">";
}
示例12: copyFromTdb
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
private void copyFromTdb( Dataset dataset ) throws RepositoryException {
ValueFactory vf = rc.getValueFactory();
if ( dataset.supportsTransactions() ) {
dataset.begin( ReadWrite.READ );
}
// Get model inside the transaction
Model model = dataset.getDefaultModel();
StmtIterator si = model.listStatements();
try {
rc.begin();
while ( si.hasNext() ) {
Statement stmt = si.next();
com.hp.hpl.jena.rdf.model.Resource rsr = stmt.getSubject();
Property pred = stmt.getPredicate();
RDFNode val = stmt.getObject();
Node valnode = val.asNode();
Resource sub;
try {
sub = ( rsr.isAnon()
? vf.createBNode( valnode.getBlankNodeLabel() )
: vf.createURI( rsr.toString() ) );
}
catch ( UnsupportedOperationException uoo ) {
log.warn( uoo, uoo );
continue;
}
URI pred2 = vf.createURI( pred.toString() );
Value val2;
if ( val.isLiteral() ) {
Literal lit = val.asLiteral();
String dtstr = lit.getDatatypeURI();
URI dt = ( null == dtstr ? null : vf.createURI( dtstr ) );
String langstr = lit.getLanguage();
if ( null == dt ) {
if ( langstr.isEmpty() ) {
val2 = vf.createLiteral( lit.toString() );
}
else {
val2 = vf.createLiteral( lit.toString(), langstr );
}
}
else {
val2 = vf.createLiteral( lit.toString(), dt );
}
}
else {
if ( val.isAnon() ) {
val2 = vf.createBNode( valnode.getBlankNodeLabel() );
}
else {
val2 = vf.createURI( val.toString() );
}
}
rc.add( sub, pred2, val2 );
}
rc.commit();
}
catch ( RepositoryException re ) {
rc.rollback();
throw re;
}
finally {
if ( dataset.supportsTransactions() ) {
dataset.end();
}
}
}
示例13: isTypeOf
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
boolean isTypeOf(RDFNode node) {
if (!node.isLiteral()) return false;
Literal l = node.asLiteral();
return XSD.xstring.getURI().equals(l.getDatatypeURI())
|| (l.getDatatypeURI() == null && "".equals(l.getLanguage()));
}
示例14: object
import com.hp.hpl.jena.rdf.model.Literal; //导入方法依赖的package包/类
private void object(TreeWriter tree, RDFNode node) {
if (node.isLiteral()) {
Literal lit = node.asLiteral();
String text = lit.getString();
String lang = lit.getLanguage();
String type = lit.getDatatypeURI();
if (lang == null || "".equals(lang)) {
lang = null;
} else {
lang = escapeXml(lang);
}
if (lang == null) {
if (type == null) {
type = "http://www.w3.org/2001/XMLSchema#string";
}
type = escapeXml(type);
} else {
type = null;
}
tree.addStartElement(sem_object);
if (lang != null) {
tree.addAttribute(XProcConstants.xml_lang, lang);
}
if (type != null) {
tree.addAttribute(_datatype, type);
}
tree.startContent();
tree.addText(escapeXml(text));
tree.addEndElement();
} else if (node.isAnon()) {
String uri = "http://marklogic.com/semantics/blank/" + Long.toHexString(
fuse(scramble((long)node.hashCode()),fuse(scramble(milliSecs),randomValue)));
tree.addStartElement(sem_object);
tree.startContent();
tree.addText(uri);
tree.addEndElement();
} else {
tree.addStartElement(sem_object);
tree.startContent();
tree.addText(escapeXml(node.toString()));
tree.addEndElement();
}
}