本文整理汇总了Java中org.semanticweb.owlapi.model.OWLLiteral.getDatatype方法的典型用法代码示例。如果您正苦于以下问题:Java OWLLiteral.getDatatype方法的具体用法?Java OWLLiteral.getDatatype怎么用?Java OWLLiteral.getDatatype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.semanticweb.owlapi.model.OWLLiteral
的用法示例。
在下文中一共展示了OWLLiteral.getDatatype方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getType
import org.semanticweb.owlapi.model.OWLLiteral; //导入方法依赖的package包/类
private static String getType(OWLLiteral literal) {
OWLDatatype datatype = literal.getDatatype();
String type = null;
if (datatype.isString() || datatype.isRDFPlainLiteral()) {
// do nothing
}
else if (datatype.isBuiltIn()) {
type = datatype.getBuiltInDatatype().getPrefixedName();
}
return type;
}
示例2: owlLiteralToValue
import org.semanticweb.owlapi.model.OWLLiteral; //导入方法依赖的package包/类
/**
* Transforms OWLLiteral to a plain Java object (boxed primitive or date/time).
*
* @param literal The literal to transform
* @return Transformed value
* @throws IllegalArgumentException If the literal is of unsupported type
*/
public static Object owlLiteralToValue(final OWLLiteral literal) {
if (literal.isRDFPlainLiteral()) {
return literal.getLiteral();
} else if (literal.getDatatype().isBuiltIn())
switch (literal.getDatatype().getBuiltInDatatype()) {
case XSD_SHORT:
return Short.parseShort(literal.getLiteral());
case XSD_LONG:
return Long.parseLong(literal.getLiteral());
case XSD_INT:
case XSD_INTEGER:
return Integer.parseInt(literal.getLiteral());
case XSD_DOUBLE:
case XSD_DECIMAL:
return Double.parseDouble(literal.getLiteral());
case XSD_FLOAT:
return Float.parseFloat(literal.getLiteral());
case XSD_STRING:
case RDF_XML_LITERAL:
case RDF_LANG_STRING:
return literal.getLiteral();
case XSD_BOOLEAN:
return Boolean.parseBoolean(literal.getLiteral());
case XSD_ANY_URI:
return URI.create(literal.getLiteral());
case XSD_DATE_TIME_STAMP:
case XSD_DATE_TIME:
try {
return new SimpleDateFormat(DATE_TIME_FORMAT).parse(literal.getLiteral());
} catch (ParseException e) {
throw new IllegalArgumentException(
"The date time '" + literal.getLiteral() + "' cannot be parsed.");
}
}
throw new IllegalArgumentException("Unsupported datatype: " + literal.getDatatype());
}
示例3: transform
import org.semanticweb.owlapi.model.OWLLiteral; //导入方法依赖的package包/类
public static Object transform(final OWLLiteral l) {
if (l.isRDFPlainLiteral()) {
return l.getLiteral();
} else if (l.getDatatype().isBuiltIn())
switch (l.getDatatype().getBuiltInDatatype()) {
case XSD_SHORT:
return Short.parseShort(l.getLiteral());
case XSD_LONG:
return Long.parseLong(l.getLiteral());
case XSD_INT:
case XSD_INTEGER:
return Integer.parseInt(l.getLiteral());
case XSD_DOUBLE:
case XSD_DECIMAL:
return Double.parseDouble(l.getLiteral());
case XSD_FLOAT:
return Float.parseFloat(l.getLiteral());
case XSD_STRING:
case RDF_XML_LITERAL:
return l.getLiteral();
case XSD_BOOLEAN:
return Boolean.parseBoolean(l.getLiteral());
case XSD_ANY_URI:
return URI.create(l.getLiteral());
case XSD_DATE_TIME_STAMP:
case XSD_DATE_TIME:
try {
return new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss")
.parse(l.getLiteral());
} catch (ParseException e) {
throw new IllegalArgumentException("The date time '"
+ l.getLiteral() + "' cannot be parsed");
}
}
throw new IllegalArgumentException("Unsupported datatype: "
+ l.getDatatype());
}