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


Java QuerySolution.getResource方法代码示例

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


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

示例1: addRolesFromModel

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
public void addRolesFromModel(Model model){
	String sparql = "PREFIX swc: <http://data.semanticweb.org/ns/swc/ontology#> "
			+ "SELECT ?role ?roletype "
			+ "WHERE{?role a swc:Chair . ?role a ?roletype . filter(?roletype != swc:Chair)}";
	Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
	QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
	ResultSet resultSet = queryExecution.execSelect();
	
	Model tmp = ModelFactory.createDefaultModel();
	while(resultSet.hasNext()){
		QuerySolution querySolution = resultSet.next();
		Resource role = querySolution.getResource("role");
		Resource roleType = querySolution.getResource("roletype");
		tmp.add(role, RDF.type, roleType);
	}
	
	
	
	//ResultSetFormatter.out(System.out, resultSet);
	
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:22,代码来源:RoleKB.java

示例2: create

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
public void create(Model model) {

		Property id = model
				.createProperty("http://www.ontologydesignpatterns.org/ont/eswc/ontology.owl#eswcId");

		String sparql = "SELECT ?person " + "WHERE{?person a <" + FOAF.Person
				+ ">}";
		Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
		QueryExecution queryExecution = QueryExecutionFactory.create(query,
				model);

		ResultSet resultSet = queryExecution.execSelect();
		for (int i = 1; resultSet.hasNext(); i++) {
			QuerySolution solution = resultSet.next();
			Resource person = solution.getResource("person");
			person.addLiteral(id,
					model.createTypedLiteral(i, XSDDatatype.XSDpositiveInteger));
		}
	}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:20,代码来源:AppIDCreator.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: getMetadataTypeIfExists

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
public MetadataType getMetadataTypeIfExists(URI uri) throws ModelException {
	String sparql = "SELECT ?metadataTypeURI WHERE { VALUES ?metadataTypeURI { ?suppliedURI } . ?metadataTypeURI a owl:DatatypeProperty .  ?metadataTypeURI rdfs:range ?range . }";
	ParameterizedSparqlString findConceptSchemeSparql = new ParameterizedSparqlString(model);
	findConceptSchemeSparql.setCommandText(sparql);
	findConceptSchemeSparql.setParam("suppliedURI", model.getResource(uri.toString()));
	
	Query query = QueryFactory.create(findConceptSchemeSparql.asQuery());

	QueryExecution qexec = QueryExecutionFactory.create(query, model);
	ResultSet resultSet = qexec.execSelect();

	MetadataType metadataType = null;
	while (resultSet.hasNext()) {
		QuerySolution querySolution = resultSet.next();
		Resource range = querySolution.getResource("?range");
		if (XSD.xstring.equals(range)) {
			metadataType = new StringMetadataType(model, querySolution.getResource("?metadataTypeURI"));
		} else if (XSD.date.equals(range)) {
			metadataType = new CalendarMetadataType(model, querySolution.getResource("?metadataTypeURI"));
		} else if (XSD.xboolean.equals(range)) {
			metadataType = new BooleanMetadataType(model, querySolution.getResource("?metadataTypeURI"));
		} else {
			throw new ModelException(String.format("Unable to determine range for metadata type with URI: '%s'", uri));
		}
	}
	return metadataType;
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:28,代码来源:SemaphoreModel.java

示例6: getRelationshipType

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
public RelationshipType getRelationshipType(URI uri) throws ModelException {
	String sparql = 
			  "select ?relationshipTypeUri ?relationshipBaseType ?inverseRelationshipType where {"
			+ "  ?relationshipTypeUri rdfs:subPropertyOf* ?relationshipBaseType ."
			+ "  VALUES ?relationshipTypeUri { ?suppliedURI }"
			+ "  VALUES ?relationshipBaseType { skos:related skos:broader skos:narrower skosxl:altLabel }"
			+ "  OPTIONAL { ?relationshipTypeUri owl:inverseOf ?inverseRelationshipType }"
			+"}";
	ParameterizedSparqlString findRelationshipTypeSparql = new ParameterizedSparqlString(model);
	findRelationshipTypeSparql.setCommandText(sparql);
	findRelationshipTypeSparql.setParam("suppliedURI", model.getResource(uri.toString()));
	
	Query query = QueryFactory.create(findRelationshipTypeSparql.asQuery());

	QueryExecution qexec = QueryExecutionFactory.create(query, model);
	ResultSet resultSet = qexec.execSelect();

	RelationshipType relationshipType = null;
	while (resultSet.hasNext()) {
		QuerySolution querySolution = resultSet.next();
		Resource relationshipTypeResource = querySolution.getResource("?relationshipTypeUri");
		Resource inverseRelationshipTypeResource = querySolution.getResource("?inverseRelationshipType");
		Resource relationshipBaseTypeResource = querySolution.getResource("?relationshipBaseType");
		if ("broader".equals(relationshipBaseTypeResource.getLocalName())) {
			relationshipType = new HasBroaderRelationshipType(model, relationshipTypeResource, inverseRelationshipTypeResource);
		} else if ("narrower".equals(relationshipBaseTypeResource.getLocalName())) {
			relationshipType = new HasNarrowerRelationshipType(model, relationshipTypeResource, inverseRelationshipTypeResource);
		} else if ("related".equals(relationshipBaseTypeResource.getLocalName())) {
			relationshipType = new AssocativeRelationshipType(model, relationshipTypeResource, inverseRelationshipTypeResource);
		} else if ("altLabel".equals(relationshipBaseTypeResource.getLocalName())) {
			relationshipType = new HasEquivalentRelationshipType(model, relationshipTypeResource);
		} else {
			throw new ModelException("Unrecognized base type: '%s' for relationship '%s'", relationshipBaseTypeResource.getLocalName(), uri.toString());
		}
	}
	return relationshipType;
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:38,代码来源:SemaphoreModel.java

示例7: 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

示例8: onNext

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
@Override
public void onNext(Model description) {
  try {
    long startTimestamp = System.currentTimeMillis();
    ResultSet metrics = query(description, METRICS_QUERY);
    while (metrics.hasNext()) {
      QuerySolution qs = metrics.next();
      String timestamp = qs.getLiteral(TIMESTAMP).getString();
      String sensorUri = qs.getResource(SENSOR_URI).getURI();
      Resource featureOfInterestResource = qs.getResource(FEATURE_OF_INTEREST);
      String value = qs.getLiteral(VALUE).getString();
      String property = qs.getResource(PROPERTY).getURI();
      if (StringUtils.isNotBlank(value)
          && StringUtils.isNotBlank(property)
          && StringUtils.isNotBlank(timestamp)
          && StringUtils.isNoneBlank(sensorUri)) {
        String featureOfInterest = null;
        if (featureOfInterestResource != null) {
          featureOfInterest = featureOfInterestResource.getURI();
        }
        TSDBClient.getInstance().write(new Observation(system_id,
            sensorUri.substring(sensorUri.lastIndexOf("/") + 1),
            timestamp, property, featureOfInterest, value));
      } else {
        logger.warn("Required properties not found!");
      }
    }
    logger.debug("Observation written in {} seconds",
        System.currentTimeMillis() - startTimestamp);
  } catch (Throwable ex) {
    logger.error(ex.getMessage(), ex);
  }
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:34,代码来源:ObservationListener.java

示例9: findDriverPidByDeviceId

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
public String findDriverPidByDeviceId(String deviceId) {
  String query = GET_DRIVER_PID_BY_SYSTEM_ID.replace("${SYSTEM_ID}", deviceId);
  ResultSet resultSet = store.select(query);
  if (resultSet.hasNext()) {
    QuerySolution qs = resultSet.next();
    Resource pid = qs.getResource("pid");
    String driverUri = pid.getURI();
    return driverUri.replace("urn:semiot:drivers:", "");
  } else {
    return null;
  }
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:13,代码来源:DirectoryServiceImpl.java

示例10: list

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
public Collection<Event> list(){
	
	Collection<Event> events = new ArrayList<Event>();
	
	String sparql = "SELECT DISTINCT ?event "
			+ "WHERE { "
			+ "{?event <" + SWC.isSuperEventOf + "> ?super} "
			+ "UNION "
			+ "{?event <" + SWC.isSubEventOf + "> ?sub} "
			+ "UNION "
			+ "{?event a ?type . ?type <" + RDFS.subClassOf + "> <" + SWC.OrganisedEvent + ">} "
			//+ "?s <" + SWC.isSuperEventOf + "> ?super . "
			//+ "FILTER (!BOUND(?super)) "
			+ "}";
	
	Model unionModel = ModelFactory.createDefaultModel();
	unionModel.add(model);
	unionModel.add(swdfOnt);
	
	
	ResultSet resultSet = QueryExecutor.execSelect(unionModel, sparql);
	
	String confAcronym = conferenceEvent.getAcronym();
	confAcronym = confAcronym.toLowerCase().replaceAll(" ", "");
	
	while(resultSet.hasNext()){
		QuerySolution querySolution = resultSet.next();
		Resource eventRes = querySolution.getResource("event");
		
		Event event = new Event(eventRes, confAcronym);
		swdf2confMapping.put(eventRes, event.asConfResource());
		
		events.add(new Event(eventRes, confAcronym));
			
	}
	
	return events;
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:39,代码来源:Events.java

示例11: 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

示例12: findNodeServices

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
private static Map<Resource, ConfNodeTable> findNodeServices(Model model, ConfCluster confCluster, Map<Resource, DataServer> servers) {
    String qsNodeServices = StrUtils.strjoinNL(prefixes,
                                               "SELECT * {",
                                               " ?svc a :NodeService ;",
                                               "    OPTIONAL { ?svc :name ?name } ",
                                               "    OPTIONAL { ?svc :servers ?sList }",
                                               "}") ;
    Map<Resource, ConfNodeTable> svcs = new LinkedHashMap<>() ;
    for ( QuerySolution row : Q.queryToList(model, qsNodeServices) ) {
        //@@ Check one nodetable.
        Resource svc = row.getResource("svc") ;
        if ( svcs.containsKey(svc) )
            throw new LizardException("Malform declaration for: "+svc) ;
        String name = Q.getStringOrNull(row, "name") ;
        if ( name == null )
            throw new LizardException("No name for NodeService: "+svc) ;
        Resource list = Q.getResourceOrNull(row, "sList") ;
        if ( list == null ) 
            throw new LizardException(name+" : No shard list for NodeService") ;
        List<Resource> sList = Q.listResources(list) ;

        FmtLog.debug(logConf, "Node service <%s>:%s", svc.getURI(), name) ;

        int N = sList.size() ;
        ConfNodeTable confNode = new ConfNodeTable(1, N) ;
        // Process servers.
        AtomicInteger integer = new AtomicInteger(0) ;
        sList.forEach(svr -> {
            DataServer ds = servers.get(svr) ;
            if ( ds == null )
                throw new LzConfigurationException("No server found: "+svr) ;
            int i = integer.incrementAndGet() ;
            ConfNodeTableElement nt  = new ConfNodeTableElement(ds.name, ds.data, confNode, ds.addr) ;
            confCluster.eltsNodeTable.add(nt) ;
        });
        confCluster.dataset.nodeTable = confNode ;
        svcs.put(svc, confNode) ;
    }
    return svcs ; 
}
 
开发者ID:afs,项目名称:lizard,代码行数:41,代码来源:LzConfParserRDF.java

示例13: dataServers

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
/** Extract all data servers */
private static Map<Resource, DataServer> dataServers(Model model, String resourceType) {
    String qs = StrUtils.strjoinNL(prefixes,
                                   "SELECT * {",
                                   " ?nServer a "+resourceType ,
                                   "    OPTIONAL { ?nServer :name     ?name }",
                                   "    OPTIONAL { ?nServer :hostname ?host }",
                                   "    OPTIONAL { ?nServer :port     ?port }",
                                   "    OPTIONAL { ?nServer :data     ?data }",
                                   "}") ;
    Map<Resource, DataServer> servers = new HashMap<>() ;
    for ( QuerySolution row : Q.queryToList(model, qs) ) {
        Resource svr = row.getResource("nServer") ;
        String name = Q.getStringOrNull(row, "name") ;
        if ( name == null )
            throw new LizardException("No name for "+svr) ;
        String host = Q.getStringOrNull(row, "host") ;
        if ( host == null )
            throw new LizardException(name+" : No host") ;
        String p = Q.getStringOrNull(row, "port") ;
        if ( p == null )
            throw new LizardException(name+" : No port") ;
        int port = Integer.parseInt(p) ;

        String data = Q.getStringOrNull(row, "data") ;
        if ( data == null )
            throw new LizardException(name+" : No data location") ;

        VNodeAddr addr = VNodeAddr.create(host, port) ;
        DataServer ds = new DataServer(svr, name, data, addr) ;
        servers.put(svr, ds) ;
    }
    return servers ;
}
 
开发者ID:afs,项目名称:lizard,代码行数:35,代码来源:LzConfParserRDF.java

示例14: 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

示例15: createNodes

import org.apache.jena.query.QuerySolution; //导入方法依赖的package包/类
public static Node createNodes(CsvTupler aCsvTupler, List<List<String>> csvRows, Model model, String query){

      try {
        // the query must have '?node' as a result
        if(model == null || query == null){
           return null;
        }		

        Query qry = QueryFactory.create(query);
        QueryExecution qe = QueryExecutionFactory.create(qry, model);
        ResultSet rs = qe.execSelect();

        List<Node> nodes = new ArrayList<Node>();

        while (rs.hasNext())
        {
            QuerySolution sol = rs.nextSolution();
            Resource res = sol.getResource("node");
            if (res.getProperty(RDF.type).getObject().asResource().getLocalName().equals("Node")) {
              nodes.add(new Node(aCsvTupler, csvRows, model, res));
            }
            else {
              System.out.println(res.getProperty(RDF.type).getObject().asResource().getURI());
              System.out.println(res.getProperty(RDF.type).getObject().asResource().getLocalName());
              return null;
            }
        }

        qe.close();

        Node root = buildTree(model, nodes);
        aCsvTupler.setNodes(nodes);
        if (setOffsets(root) == false)
          throw new Exception("Can't set row and columns offsets");

        if (setOffsetsRelativeTo(root) == false)
          throw new Exception("Can't set relative row and columns offsets");        

        return root;
        
      } catch (Exception e) {
        System.out.println(e);
        return null;
      }
    }
 
开发者ID:tag42git,项目名称:CsvTupler,代码行数:46,代码来源:NodeFactory.java


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