当前位置: 首页>>代码示例>>Java>>正文


Java LiteralLabel.getLexicalForm方法代码示例

本文整理汇总了Java中org.apache.jena.graph.impl.LiteralLabel.getLexicalForm方法的典型用法代码示例。如果您正苦于以下问题:Java LiteralLabel.getLexicalForm方法的具体用法?Java LiteralLabel.getLexicalForm怎么用?Java LiteralLabel.getLexicalForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.jena.graph.impl.LiteralLabel的用法示例。


在下文中一共展示了LiteralLabel.getLexicalForm方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:dice-group,项目名称:RDF2PT,代码行数:43,代码来源:LiteralConverterPortuguese.java

示例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;
}
 
开发者ID:dice-group,项目名称:RDF2PT,代码行数:32,代码来源:LiteralConverter.java

示例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;
}
 
开发者ID:dice-group,项目名称:RDF2PT,代码行数:37,代码来源:LiteralConverterFrench.java

示例4: doSparqlQuery

import org.apache.jena.graph.impl.LiteralLabel; //导入方法依赖的package包/类
private Map<String, List<LabeledEntity>> doSparqlQuery(String sparqlQuery) {
    logger.debug(marker, "Executing: {}", sparqlQuery);

    long startTime = System.currentTimeMillis();

    Map<String, List<LabeledEntity>> result = new LinkedHashMap<>();
    EntitySearcher entitySearcher = core.createEntitySearcher();

    try (QueryExecution qexec = QueryExecutionFactory.create(sparqlQuery, core.getGraphModel(dbId))) {
        ResultSet results = qexec.execSelect();

        while (results.hasNext()) {
            Binding jBinding = results.nextBinding();
            Iterator<Var> vars = jBinding.vars();
            while (vars.hasNext()) {
                Var jVar = vars.next();

                if (!jBinding.get(jVar).isLiteral()) {
                    String id = jBinding.get(jVar).getURI();
                    List<LabeledEntity> entities = result.computeIfAbsent(jVar.getVarName(), (v) -> new ArrayList<>());
                    LabeledEntity labeledEntity = ns.isFromMainNS(id) ? entitySearcher.getEntity(dbId, id) : ModelUtils.createInstance(id);
                    entities.add(labeledEntity);
                } else {
                    LiteralLabel lit = jBinding.get(jVar).getLiteral();
                    ValueEntity valueEntity = new ValueEntity(lit.getLexicalForm(), lit.getDatatype().getURI(), lit.language());
                    result.computeIfAbsent(jVar.getVarName(), (v) -> new ArrayList<>()).add(valueEntity);
                }
            }
        }
    }

    long millis = System.currentTimeMillis() - startTime;

    if (!result.isEmpty()) {
        logger.info(marker, "SPARQL {} query took {}s", sparqlQuery, millis / 1000.0);
    }
    else {
        logger.warn(marker, "No matches for {}", sparqlQuery);
    }

    return result;
}
 
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:43,代码来源:JenaGraphSearcher.java

示例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, 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;
}
 
开发者ID:dice-group,项目名称:RDF2PT,代码行数:47,代码来源:LiteralConverterPortuguese.java

示例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, 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;
    }
 
开发者ID:dice-group,项目名称:RDF2PT,代码行数:44,代码来源:LiteralConverter.java

示例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, 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;
}
 
开发者ID:dice-group,项目名称:RDF2PT,代码行数:47,代码来源:LiteralConverterFrench.java

示例8: 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;
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:46,代码来源:LiteralConverter.java


注:本文中的org.apache.jena.graph.impl.LiteralLabel.getLexicalForm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。