本文整理汇总了Java中org.apache.jena.graph.impl.LiteralLabel.getDatatype方法的典型用法代码示例。如果您正苦于以下问题:Java LiteralLabel.getDatatype方法的具体用法?Java LiteralLabel.getDatatype怎么用?Java LiteralLabel.getDatatype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.graph.impl.LiteralLabel
的用法示例。
在下文中一共展示了LiteralLabel.getDatatype方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import org.apache.jena.graph.impl.LiteralLabel; //导入方法依赖的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;
}
示例2: convert
import org.apache.jena.graph.impl.LiteralLabel; //导入方法依赖的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;
}
示例3: convert
import org.apache.jena.graph.impl.LiteralLabel; //导入方法依赖的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;
}
示例4: convertDateLiteral
import org.apache.jena.graph.impl.LiteralLabel; //导入方法依赖的package包/类
private String convertDateLiteral(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
try {
Object value = lit.getValue();
if (value instanceof XSDDateTime) {
Calendar calendar = ((XSDDateTime) value).asCalendar();
if (dt.equals(XSDDatatype.XSDgMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgMonthDay)) {
s = calendar.get(Calendar.DAY_OF_MONTH)
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
} else if (dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.get(Calendar.DAY_OF_MONTH) + " de "
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, PORTUGUESE_LOCAL) + " de "
+ calendar.get(Calendar.YEAR);
// dateFormat.format(calendar.getTime());
}
}
} catch (DatatypeFormatException | IllegalDateTimeFieldException e) {
logger.error("Conversion of date literal " + lit + " failed. Reason: " + e.getMessage());
// fallback
// DateTime time = ISODateTimeFormat.dateTime
DateTime time;
try {
time = ISODateTimeFormat.dateTimeParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd 'de' MMMM 'de' YYYY", PORTUGUESE_LOCAL);
}
}
}
return s;
}
示例5: convertDateLiteral
import org.apache.jena.graph.impl.LiteralLabel; //导入方法依赖的package包/类
private String convertDateLiteral(LiteralLabel lit){
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
try {
Object value = lit.getValue();
if (value instanceof XSDDateTime) {
Calendar calendar = ((XSDDateTime) value).asCalendar();
if(dt.equals(XSDDatatype.XSDgMonth)){
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL);
} else if(dt.equals(XSDDatatype.XSDgMonthDay)){
s = calendar.get(Calendar.DAY_OF_MONTH) + calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL);
} else if(dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL) + " " + calendar.get(Calendar.YEAR);
} else if(dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL) + " " + calendar.get(Calendar.DAY_OF_MONTH)
+ ", " + calendar.get(Calendar.YEAR);
// dateFormat.format(calendar.getTime());
}
}
} catch (DatatypeFormatException | IllegalDateTimeFieldException e) {
logger.error("Conversion of date literal " + lit + " failed. Reason: " + e.getMessage());
//fallback
// DateTime time = ISODateTimeFormat.dateTime
DateTime time;
try {
time = ISODateTimeFormat.dateTimeParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
}
}
}
return s;
}
示例6: convertDateLiteral
import org.apache.jena.graph.impl.LiteralLabel; //导入方法依赖的package包/类
private String convertDateLiteral(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
try {
Object value = lit.getValue();
if (value instanceof XSDDateTime) {
Calendar calendar = ((XSDDateTime) value).asCalendar();
if (dt.equals(XSDDatatype.XSDgMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgMonthDay)) {
s = calendar.get(Calendar.DAY_OF_MONTH)
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
} else if (dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.get(Calendar.DAY_OF_MONTH) + " "
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, FRENCH_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
// dateFormat.format(calendar.getTime());
}
}
} catch (DatatypeFormatException | IllegalDateTimeFieldException e) {
logger.error("Conversion of date literal " + lit + " failed. Reason: " + e.getMessage());
// fallback
// DateTime time = ISODateTimeFormat.dateTime
DateTime time;
try {
time = ISODateTimeFormat.dateTimeParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd MMMM YYYY", FRENCH_LOCAL);
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd MMMM YYYY", FRENCH_LOCAL);
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("dd MMMM YYYY", FRENCH_LOCAL);
}
}
}
return s;
}
示例7: convertDateLiteral
import org.apache.jena.graph.impl.LiteralLabel; //导入方法依赖的package包/类
private String convertDateLiteral(LiteralLabel lit) {
RDFDatatype dt = lit.getDatatype();
String s = lit.getLexicalForm();
try {
Object value = lit.getValue();
if (value instanceof XSDDateTime) {
Calendar calendar = ((XSDDateTime) value).asCalendar();
if (dt.equals(XSDDatatype.XSDgMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgMonthDay)) {
s = calendar.get(Calendar.DAY_OF_MONTH)
+ calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL);
} else if (dt.equals(XSDDatatype.XSDgYearMonth)) {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL) + " "
+ calendar.get(Calendar.YEAR);
} else if (dt.equals(XSDDatatype.XSDgYear)) {
s = "" + calendar.get(Calendar.YEAR);
} else {
s = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, ENGLISH_LOCAL) + " "
+ calendar.get(Calendar.DAY_OF_MONTH) + ", " + calendar.get(Calendar.YEAR);
// dateFormat.format(calendar.getTime());
}
}
} catch (DatatypeFormatException | IllegalDateTimeFieldException e) {
logger.error("Conversion of date literal " + lit + " failed. Reason: " + e.getMessage());
// fallback
// DateTime time = ISODateTimeFormat.dateTime
DateTime time;
try {
time = ISODateTimeFormat.dateTimeParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
} catch (Exception e1) {
try {
time = ISODateTimeFormat.localDateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
} catch (Exception e2) {
e2.printStackTrace();
time = ISODateTimeFormat.dateParser().parseDateTime(lit.getLexicalForm());
s = time.toString("MMMM dd, yyyy");
}
}
}
return s;
}