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


Java QuerySolution.getLiteral方法代码示例

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


在下文中一共展示了QuerySolution.getLiteral方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLabel

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
 * Return the label for this object in the selected language
 * @param language - the language for which the label is requested
 * @return - the label in the requested language.
 * @throws ModelException - thrown if there are multiple labels present for this object in this language
 */
public Label getLabel(Language language) throws ModelException {
	String sparql = "SELECT ?label WHERE { ?objectURI rdfs:label ?label . FILTER(LANG(?label) = STR(?labelLanguage)) }";
	ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
	parameterizedSparql.setCommandText(sparql);
	parameterizedSparql.setParam("objectURI", resource);
	parameterizedSparql.setParam("labelLanguage", model.createLiteral(language.getCode(), ""));
	
	Query query = QueryFactory.create(parameterizedSparql.asQuery());

	QueryExecution qexec = QueryExecutionFactory.create(query, model);
	ResultSet resultSet = qexec.execSelect();
	
	if (!resultSet.hasNext()) return null;
	
	QuerySolution querySolution = resultSet.next();
	Label label = new Label(querySolution.getLiteral("label"));
	
	if (!resultSet.hasNext()) return label;
	
	throw new ModelException("%s has more than one label in language '%s'", resource.getURI(), language.getCode());
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:28,代码来源:ObjectWithURI.java

示例2: getCount

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
public static int getCount(String q, Model m) {
    Query query = QueryFactory.create(q);
    QueryExecution queryExec = QueryExecutionFactory.create(query, m);
    ResultSet rs = queryExec.execSelect();
    String vName = "";
    for (String v: rs.getResultVars()) {
        if (v.contains("count")) {
            vName = v;
            break;
        }
    }
    
    while (rs.hasNext()) {
        QuerySolution s = rs.nextSolution();
        Literal c = s.getLiteral(vName);
        queryExec.close();
        return c.getInt();
    }   
    queryExec.close();
    return 0;
}
 
开发者ID:albangaignard,项目名称:EDAMetrics,代码行数:22,代码来源:Queries.java

示例3: getSummaries

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
 * generates the map of paperId - paperTitle
 * 
 * @param model
 * @return
 */
public Map<String, String> getSummaries(Model[] models) {

	Map<String, String> titlesMap = new HashMap<String, String>();
	for (Model model : models) {
	    if(model != null){
   			String sparql = "PREFIX ical: <http://www.w3.org/2002/12/cal/icaltzd#> "
   					+ "SELECT ?event ?summary "
   					+ "WHERE{"
   					+ "    ?event ical:summary ?summary" + "}";
   			Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
   			QueryExecution queryExecution = QueryExecutionFactory.create(query,
   					model);
   			ResultSet resultSet = queryExecution.execSelect();
   			while (resultSet.hasNext()) {
   				QuerySolution querySolution = resultSet.next();
   				Resource paper = querySolution.getResource("event");
   				Literal title = querySolution.getLiteral("summary");
   				String titleString = title.getLexicalForm().replaceAll(" +",
   						" ");
   				titlesMap.put(paper.getURI(), titleString);
   			}
	    }
	}
	return titlesMap;
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:32,代码来源:CalendarAlignerWithSessions.java

示例4: listVersions

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
@Override
public List<VersionInfo> listVersions(String uri) {
    ResultSet rs = selectAll(getDefaultModel(), VERSION_LIST_QUERY,
            Prefixes.getDefault(),
            createBindings("root", ResourceFactory.createResource(uri)));
    List<VersionInfo> results = new ArrayList<VersionInfo>();
    while (rs.hasNext()) {
        QuerySolution soln = rs.next();
        VersionInfo vi = new VersionInfo(soln.getResource("version"),
                soln.getLiteral("info"), soln.getLiteral("from"),
                soln.getLiteral("to"));
        Resource replaces = soln.getResource("replaces");
        if (replaces != null) {
            vi.setReplaces(replaces.getURI());
        }
        results.add(vi);
    }
    return results;
}
 
开发者ID:UKGovLD,项目名称:registry-core,代码行数:20,代码来源:StoreBaseImpl.java

示例5: getAltTermMap

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
 * Takes an altLabel URI and returns a map with the Alt Label Text as the key and the Concept Resource object as the value.  
 * @param model - the underlying model containing the Semaphore model
 * @param altTermRelationship - The altTermRelationship property.  If Null, this will default to SKOSXL.altLabel.
 * @param language - The label language to use.  All other language labels will be discarded.  A language of null or empty string is considered language neutral.
 * @param throwOnDuplicate - If true and there is a duplicate label / key, we will throw an exception.  Otherwise, a warning will be logged.
 * @return A Map of AltLabel string literals (one for each language) as the key and the value of is the Concept Resource object.
 * @throws ModelException - if throwOnDuplicate is set and a duplicate is encountered
 */
public static Map<String, Resource> getAltTermMap(Model model, Property altTermRelationship, String language, boolean throwOnDuplicate) throws ModelException {
	if(altTermRelationship == null){
		altTermRelationship = SKOSXL.altLabel;
	}
	if(language == null) language = "";
	
	ParameterizedSparqlString findConceptLabelsSparql = new ParameterizedSparqlString();
	findConceptLabelsSparql.setCommandText("SELECT ?conceptUri ?label { ?conceptUri ?altLabelURI ?labelUri . ?labelUri ?skosxlLiteralForm ?label. }");
	findConceptLabelsSparql.setParam("altLabelURI", altTermRelationship);
	findConceptLabelsSparql.setParam("skosxlPrefLabel", SKOSXL.prefLabel);
	findConceptLabelsSparql.setParam("skosxlLiteralForm", SKOSXL.literalForm);

	Query query = QueryFactory.create(findConceptLabelsSparql.asQuery());

	QueryExecution qexec = QueryExecutionFactory.create(query, model);
	ResultSet resultSet = qexec.execSelect();
	
	Map<String, Resource> labels = new HashMap<String, Resource>();
	while (resultSet.hasNext()) {
		QuerySolution querySolution = resultSet.next();
		Literal label = querySolution.getLiteral("?label");
		if(labels.containsKey(label.getString())){
			String errorString = String.format("The alternate label %s is already included in this map.  Skipping.", label);
			if(throwOnDuplicate) throw new ModelException(errorString);
			logger.warn(errorString);
		}
		else if(label.getLanguage().compareTo(language) == 0){
			
			Resource conceptResource = querySolution.getResource("?conceptUri");
			labels.put(label.getString(), conceptResource);
		}
	}
	return labels;
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:44,代码来源:Utils.java

示例6: getContributors

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
private Set<String> getContributors(QuerySolution result) {
	Set<String> contributors = new HashSet<>();
	if (result.getLiteral("contributors") != null) {
		for (String contributor : result.getLiteral("contributors").getLexicalForm().split("\\|")) {
			contributors.add(contributor);
		}
	}
	return Collections.unmodifiableSet(contributors);
}
 
开发者ID:geneontology,项目名称:minerva,代码行数:10,代码来源:GPADSPARQLExport.java

示例7: getTitles

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
 * generates the map of paperId - paperTitle
 * 
 * @param model
 * @return
 */
public Map<String, String> getTitles(Model model) {
	Map<String, String> titlesMap = new HashMap<String, String>();
	// TODO check why we have two different expressions for titles
	String sparql = "PREFIX dc: <http://purl.org/dc/elements/1.1/> "
			+ "PREFIX dc-terms: <http://purl.org/dc/terms/> "
			+ "SELECT * WHERE {" +

			"{" + "SELECT ?paper ?title " + "WHERE{"
			+ "    ?paper dc:title ?title" + "}" + "}" + "UNION" +

			"{" + "SELECT ?paper ?title " + "WHERE{"
			+ "    ?paper dc-terms:title ?title" + "}" + "}" + "}";

	Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
	QueryExecution queryExecution = QueryExecutionFactory.create(query,
			model);
	ResultSet resultSet = queryExecution.execSelect();
	while (resultSet.hasNext()) {
		QuerySolution querySolution = resultSet.next();
		Resource paper = querySolution.getResource("paper");
		Literal title = querySolution.getLiteral("title");
		String titleString = title.getLexicalForm().replaceAll(" +", " ");
		if (titleString.endsWith("."))
			titleString = titleString
					.substring(0, titleString.length() - 1);
		titlesMap.put(paper.getURI(), titleString);
	}

	return titlesMap;
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:37,代码来源:CalendarAlignerWithSessions.java

示例8: queryService

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
 * 
 * @param service
 * @param sparqlQueryString
 * @param solutionConcept
 *            the target concept to extract from the query, tye name should
 *            be the same as the name of the target variable in
 *            sparqlQueryString
 * @return the set of string from literal results
 */
public Set<String> queryService(String service, String sparqlQueryString,
		String solutionConcept) {
	Set<String> resulStrings = new HashSet<String>();

	Query query = QueryFactory.create(sparqlQueryString);

	QueryExecution qexec = QueryExecutionFactory.sparqlService(service,
			query);

	try {
		ResultSet results = qexec.execSelect();

		for (; results.hasNext();) {
			QuerySolution soln = results.nextSolution();

			Literal l;
			try {
				if (soln.get(solutionConcept).isLiteral()) {
					l = soln.getLiteral(solutionConcept);
					resulStrings.add(l.getString());
				} else {
					RDFNode u = soln.get(solutionConcept);
					resulStrings.add(u.toString());
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	} finally {
		qexec.close();
	}
	return resulStrings;
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:45,代码来源:GenerateNameGraph.java

示例9: listMembers

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
@Override
public List<RegisterEntryInfo> listMembers(Register register, List<FilterSpec> filters) {
    String query = REGISTER_LIST_QUERY;
    if (filters != null) {
        query = query.replace("#filtertag", FilterSpec.asQuery(filters, "entity"));
    }
    ResultSet rs = selectAll(getDefaultModel(), query,
            Prefixes.getDefault(),
            createBindings("register", register.getRoot()));
    List<RegisterEntryInfo> results = new ArrayList<RegisterEntryInfo>();
    Resource priorItem = null;
    RegisterEntryInfo prior = null;
    while (rs.hasNext()) {
        QuerySolution soln = rs.next();
        try {
            Resource item = soln.getResource("item");
            if (item.equals(priorItem)) {
                prior.addLabel(soln.getLiteral("label"));
                prior.addType(soln.getResource("type"));
            } else {
                prior = new RegisterEntryInfo(soln.getResource("status"),
                        item, soln.getResource("entity"),
                        soln.getLiteral("label"), soln.getResource("type"),
                        soln.getLiteral("notation"));
                priorItem = item;
                results.add(prior);
            }
        } catch (ClassCastException e) {
            log.warn("Skipping ill-formed resource: " + soln.get("item"));
            // Skip ill-formed resources
            // Though these should be blocked on registration
        }
    }
    return results;
}
 
开发者ID:UKGovLD,项目名称:registry-core,代码行数:36,代码来源:StoreBaseImpl.java

示例10: addAuthorList

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
private void addAuthorList(Resource confInProceedings, Model model){
	
	Resource authorList = model.createResource(confInProceedings.getURI() + "/authorList", ConferenceOntology.List);
	confInProceedings.addProperty(ConferenceOntology.hasAuthorList, authorList);
	
	String sparql = 
			"SELECT ?member ?pos "
			+ "WHERE { "
			+ "{<" + resource.getURI() + "> <http://www.cs.vu.nl/~mcaklein/onto/swrc_ext/2005/05#authorList> ?authorList} "
			+ "UNION "
			+ "{<" + resource.getURI() + "> <http://purl.org/ontology/bibo/authorList> ?authorList} "
			+ "?authorList ?p ?member . FILTER(REGEX(STR(?p), \"http://www.w3.org/1999/02/22-rdf-syntax-ns#_\")) . "
			+ "BIND(REPLACE(STR(?p), \"http://www.w3.org/1999/02/22-rdf-syntax-ns#_\", \"\") AS ?pos)" 
			+ "} "
			+ "ORDER BY ?pos";
	
	
	Model modelIn = resource.getModel();
	ResultSet resultSet = QueryExecutor.execSelect(modelIn, sparql);
	
	//ResultSetFormatter.out(System.out, resultSet);
	
	
	int itemCounter = 0;
	Resource previousAuthorListItem = null;
	Resource authorListItem = null;
	while(resultSet.hasNext()){
		if(authorListItem != null)
			previousAuthorListItem = authorListItem;
		
		QuerySolution querySolution = resultSet.next();
		Resource person = querySolution.getResource("member");
		Literal pos = querySolution.getLiteral("pos");
		authorListItem = model.createResource(confInProceedings.getURI() + "/authorList/item-" + pos.getLexicalForm(), ConferenceOntology.ListItem);
		authorListItem.addProperty(ConferenceOntology.hasContent, ModelFactory.createDefaultModel().createResource(person.getURI().replace("http://data.semanticweb.org/", "http://www.scholarlydata.org/")));	
		
		authorList.addProperty(ConferenceOntology.hasItem, authorListItem);
		
		if(itemCounter == 0){
			authorList.addProperty(ConferenceOntology.hasFirstItem, authorListItem);
		}
		else{
			authorListItem.addProperty(ConferenceOntology.previous, previousAuthorListItem);
			previousAuthorListItem.addProperty(ConferenceOntology.next, authorListItem);
		}
		
		itemCounter += 1;
		
	}
	
	if(authorListItem != null)
		authorList.addProperty(ConferenceOntology.hasLastItem, authorListItem);
	
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:55,代码来源:InProceedings.java

示例11: getOptionalLiteral

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
private static String getOptionalLiteral(QuerySolution qs, String field) {
	return qs.getLiteral(field) != null ? qs.getLiteral(field).getString() : null;		
}
 
开发者ID:CTSIatUCSF,项目名称:Crosslinks,代码行数:4,代码来源:MarengoDetailProcessor.java

示例12: useResultSet

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
public void useResultSet(ResultSet rs) {
	if (rs.hasNext()) {				
		QuerySolution qs = rs.next();
		dt = qs.getLiteral("?dt") != null ? ((XSDDateTime)qs.getLiteral("?dt").getValue()).asCalendar() : null;
	}				
}
 
开发者ID:CTSIatUCSF,项目名称:Crosslinks,代码行数:7,代码来源:SparqlPersistance.java

示例13: createFragment

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
 *
 * @param subject
 * @param predicate
 * @param object
 * @param offset
 * @param limit
 * @return
 */
@Override
protected ILinkedDataFragment createFragment(
           final ITriplePatternElement<RDFNode,String,String> subject,
           final ITriplePatternElement<RDFNode,String,String> predicate,
           final ITriplePatternElement<RDFNode,String,String> object,
           final long offset,
           final long limit )
{
    // FIXME: The following algorithm is incorrect for cases in which
    //        the requested triple pattern contains a specific variable
    //        multiple times;
    //        e.g., (?x foaf:knows ?x ) or (_:bn foaf:knows _:bn)
    // see https://github.com/LinkedDataFragments/Server.Java/issues/24

    Model model = tdb.getDefaultModel();
    QuerySolutionMap map = new QuerySolutionMap();
    if ( ! subject.isVariable() ) {
        map.add("s", subject.asConstantTerm());
    }
    if ( ! predicate.isVariable() ) {
        map.add("p", predicate.asConstantTerm());
    }
    if ( ! object.isVariable() ) {
        map.add("o", object.asConstantTerm());
    }

    query.setOffset(offset);
    query.setLimit(limit);

    Model triples = ModelFactory.createDefaultModel();

    try (QueryExecution qexec = QueryExecutionFactory.create(query, model, map)) {
        qexec.execConstruct(triples);
    }

    if (triples.isEmpty()) {
        return createEmptyTriplePatternFragment();
    }

    // Try to get an estimate
    long size = triples.size();
    long estimate = -1;

    try (QueryExecution qexec = QueryExecutionFactory.create(countQuery, model, map)) {
        ResultSet results = qexec.execSelect();
        if (results.hasNext()) {
            QuerySolution soln = results.nextSolution() ;
            Literal literal = soln.getLiteral("count");
            estimate = literal.getLong();
        }
    }

    /*GraphStatisticsHandler stats = model.getGraph().getStatisticsHandler();
    if (stats != null) {
        Node s = (subject != null) ? subject.asNode() : null;
        Node p = (predicate != null) ? predicate.asNode() : null;
        Node o = (object != null) ? object.asNode() : null;
        estimate = stats.getStatistic(s, p, o);
    }*/

    // No estimate or incorrect
    if (estimate < offset + size) {
        estimate = (size == limit) ? offset + size + 1 : offset + size;
    }

    // create the fragment
    final boolean isLastPage = ( estimate < offset + limit );
    return createTriplePatternFragment( triples, estimate, isLastPage );
}
 
开发者ID:LinkedDataFragments,项目名称:Server.Java,代码行数:79,代码来源:JenaTDBBasedRequestProcessorForTPFs.java

示例14: listDelegations

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
@Override
public List<ForwardingRecord> listDelegations() {
    List<ForwardingRecord> results = new ArrayList<>();
    Model m = getDefaultModel();
    ResultSet rs = QueryUtil.selectAll(m, DELEGATION_LIST_QUERY,
            Prefixes.getDefault());
    while (rs.hasNext()) {
        QuerySolution soln = rs.nextSolution();
        try {
            Status status = Status.forResource(soln
                    .getResource("status"));
            if (status.isAccepted()) {
                Resource record = soln.getResource("record").inModel(m);
                ForwardingRecord.Type type = Type.FORWARD;
                if (record.hasProperty(RDF.type,
                        RegistryVocab.FederatedRegister)) {
                    type = Type.FEDERATE;
                } else if (record.hasProperty(RDF.type,
                        RegistryVocab.DelegatedRegister)) {
                    type = Type.DELEGATE;
                }
                String target = soln.getResource("target").getURI();
                ForwardingRecord fr = null;
                if (type == Type.DELEGATE) {
                    DelegationRecord dr = new DelegationRecord(
                            record.getURI(), target, type);
                    Resource s = soln.getResource("subject");
                    if (s != null)
                        dr.setSubject(s);
                    Resource p = soln.getResource("predicate");
                    if (p != null)
                        dr.setPredicate(p);
                    RDFNode on = soln.get("object");
                    Resource o = null;
                    if (on.isResource()) {
                        o = on.asResource();
                    } else if (on.isLiteral()) {
                        String olit = on.asLiteral().getLexicalForm();
                        if (NameUtils.isURI(olit)) {
                            o = ResourceFactory.createResource(olit);
                        }
                    }
                    if (o != null)
                        dr.setObject(o);
                    fr = dr;
                } else {
                    fr = new ForwardingRecord(record.getURI(), target,
                            type);
                    Literal code = soln.getLiteral("code");
                    if (code != null) {
                        fr.setForwardingCode(code.getInt());
                    }
                }
                results.add(fr);
            }
        } catch (Exception e) {
            log.error(
                    "Bad delegation record for " + soln.get("record"),
                    e);
        }
    }
    return results;
}
 
开发者ID:UKGovLD,项目名称:registry-core,代码行数:64,代码来源:StoreBaseImpl.java


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