本文整理匯總了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();
}
}