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


Java QuerySolution.getLiteral方法代码示例

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


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

示例1: getGeoLocation

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
  * Gets and returns the geolocation of a POI
  * @param resource
  * @return
  */
 private static Literal getGeoLocation(String resource){
 	
 	Literal geoLocation;
 	
 	String sparqlquery= "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> \n"			
				+ "select distinct ?geolocation where {" 
				+ "<"+resource+"> geo:geometry ?geolocation.}\n"
				+ "LIMIT 1 ";
 	Query query = QueryFactory.create(sparqlquery);
  QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
  ResultSet results = qexec.execSelect();
  if (results.hasNext() ){ 				
QuerySolution soln = results.nextSolution();
geoLocation = soln.getLiteral("geolocation");
   qexec.close();
   return geoLocation;
  }
  else {
   qexec.close();
  	return null;
  }
 }
 
开发者ID:Localizr,项目名称:Localizr,代码行数:28,代码来源:GeoNamesRecommendation.java

示例2: loadClassPartitionStatistics

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
public void loadClassPartitionStatistics(OntModel voidModel) {
	Query query = QueryFactory.create(classPartitionStatisticsQuery);
	QueryExecution qexec = QueryExecutionFactory.create(query, voidModel);

	try {
		ResultSet results = qexec.execSelect();
		for (; results.hasNext();) {
			QuerySolution soln = results.nextSolution();
			OntResource dataset = soln.getResource("Dataset").as(
					OntResource.class);
			OntResource clazz = soln.getResource("Class").as(
					OntResource.class);
			Integer entities = (soln.getLiteral("Entities") != null) ? soln
					.getLiteral("Entities").getInt() : null;	
			Dataset ds = this.getDataset(dataset);		
			if (ds!=null)ds.getPartitions().addClassPartition(clazz, entities);
		}
	} catch (Exception e) {
		Log.debug(
				this,
				"Unable to execute classPartitionStatisticsQuery " + query);
	} finally {
		qexec.close();
	}
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.remediator,代码行数:26,代码来源:Datasets.java

示例3: loadPropertyPartitionStatistics

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
public void loadPropertyPartitionStatistics(OntModel voidModel) {
	Query query = QueryFactory.create(propertyPartitionStatisticsQuery);
	QueryExecution qexec = QueryExecutionFactory.create(query, voidModel);

	try {
		ResultSet results = qexec.execSelect();
		for (; results.hasNext();) {
			QuerySolution soln = results.nextSolution();
			OntResource dataset = soln.getResource("Dataset").as(
					OntResource.class);
			OntResource property = soln.getResource("Property").as(
					OntResource.class);
			Integer triples = (soln.getLiteral("Triples") != null) ? soln
					.getLiteral("Triples").getInt() : null;	
			Dataset ds = this.getDataset(dataset);		
			if (ds!=null)ds.getPartitions().addPropertyPartition(property, triples);
		}
	} catch (Exception e) {
		Log.debug(
				this,
				"Unable to execute propertyPartitionStatisticsQuery " + query);
	} finally {
		qexec.close();
	}
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.remediator,代码行数:26,代码来源:Datasets.java

示例4: queryClassPartitionStatistics

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
private void queryClassPartitionStatistics() {
	Query query = QueryFactory.create(classPartitionStatisticsQuery);
	QueryExecution qexec = QueryExecutionFactory.sparqlService(
			this.sparqlEndPoint.toString(), query);

	try {
		ResultSet results = qexec.execSelect();
		for (; results.hasNext();) {
			QuerySolution soln = results.nextSolution();
			OntResource clazz = soln.getResource("class").as(
					OntResource.class);
			Integer entities = (soln.getLiteral("count") != null) ? soln
					.getLiteral("count").getInt() : null;
			partitions.addClassPartition(clazz, entities);
		}
	} catch (Exception e) {
		Log.debug(
				Dataset.class,
				"Unable to connect to SPARQLEndpoint to execute classPartitionStatisticsQuery: "
						+ this.sparqlEndPoint.toString());
	} finally {
		qexec.close();
	}
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.remediator,代码行数:25,代码来源:Dataset.java

示例5: queryPropertyPartitionStatistics

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
protected void queryPropertyPartitionStatistics() {
	Query query = QueryFactory.create(propertyPartitionStatisticsQuery);
	QueryExecution qexec = QueryExecutionFactory.sparqlService(
			this.sparqlEndPoint.toString(), query);

	try {
		ResultSet results = qexec.execSelect();
		for (; results.hasNext();) {
			QuerySolution soln = results.nextSolution();
			OntResource property = soln.getResource("p").as(
					OntResource.class);
			Integer triples = (soln.getLiteral("count") != null) ? soln
					.getLiteral("count").getInt() : null;
			partitions.addPropertyPartition(property, triples);
		}
	} catch (Exception e) {
		Log.debug(
				Dataset.class,
				"Unable to connect to SPARQLEndpoint to execute propertyPartitionStatisticsQuery: "
						+ this.sparqlEndPoint.toString());
	} finally {
		qexec.close();
	}
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.remediator,代码行数:25,代码来源:Dataset.java

示例6: queryResultSet

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
public void queryResultSet() {

		Query q = QueryFactory.create(query);
		QueryExecution qe = QueryExecutionFactory.create(q, model);
		ResultSet rs = qe.execSelect();
		while (rs.hasNext()) {
			QuerySolution soln = rs.nextSolution();
			// RDFNode x = soln.get("?o") ; // Get a result variable by name.
			// Resource r = soln.getResource("?o"); // Get a result variable -
			// must be a resource
			Literal l = soln.getLiteral("?o"); // Get a result variable - must
												// be a literal
			literalsListDuplicates.add(l.getLexicalForm());
			literalsListNODuplicates.add(l.getLexicalForm());
		}
		// NodeIterator itr = model.listObjects();
		// while (itr.hasNext()) {
		// System.out.println(itr.next());
		// }

	}
 
开发者ID:SaudAljaloud,项目名称:RdfLiteralStats,代码行数:22,代码来源:JenaTesting.java

示例7: queryDatasetStatistics

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
private void queryDatasetStatistics() {
	Query query = QueryFactory.create(datasetStatisticsQuery);
	QueryExecution qexec = QueryExecutionFactory.sparqlService(
			this.sparqlEndPoint.toString(), query);

	try {
		ResultSet results = qexec.execSelect();
		for (; results.hasNext();) {
			// ?triples ?entities ?classes ?predicates ?subjects ?objects
			QuerySolution soln = results.nextSolution();
			triples = (soln.getLiteral("triples") != null) ? soln
					.getLiteral("triples").getInt() : null;
			entities = (soln.getLiteral("entities") != null) ? soln
					.getLiteral("entities").getInt() : null;
			classes = (soln.getLiteral("classes") != null) ? soln
					.getLiteral("classes").getInt() : null;
			properties = (soln.getLiteral("properties") != null) ? soln
					.getLiteral("properties").getInt() : null;
			distinctSubjects = (soln.getLiteral("distinctSubjects") != null) ? soln
					.getLiteral("distinctSubjects").getInt() : null;
			distinctObjects = (soln.getLiteral("distinctObjects") != null) ? soln
					.getLiteral("distinctObjects").getInt() : null;
		}
	} catch (Exception e) {
		Log.debug(Dataset.class,
				"Unable to connect to SPARQLEndpoint to execute datasetStatisticsQuery: "
						+ this.sparqlEndPoint.toString());
	} finally {
	}
	qexec.close();
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.remediator,代码行数:32,代码来源:Dataset.java

示例8: getLabel

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
public static String getLabel(String key, QuerySolution querySolution) {
  if (key == null) {
    return null;
  }
  Literal literal = querySolution.getLiteral(key);
  return literal != null ? literal.getString() : null;
}
 
开发者ID:eENVplus,项目名称:tf-exploitation-server,代码行数:8,代码来源:QuerySolutionItemExtractors.java

示例9: getLanguage

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
public static String getLanguage(String key, QuerySolution querySolution) {
  if (key == null) {
    return null;
  }
  Literal literal = querySolution.getLiteral(key);
  return literal != null ? literal.getLanguage() : null;
}
 
开发者ID:eENVplus,项目名称:tf-exploitation-server,代码行数:8,代码来源:QuerySolutionItemExtractors.java

示例10: queryResultSetToFile

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
public void queryResultSetToFile() {

		try {
			FileWriter fw = new FileWriter(literalsFile, true);
			BufferedWriter bw = new BufferedWriter(fw);
			Query q = QueryFactory.create(query);
			QueryExecution qe = QueryExecutionFactory.create(q, model);
			ResultSet rs = qe.execSelect();
			while (rs.hasNext()) {
				QuerySolution soln = rs.nextSolution();
				// RDFNode x = soln.get("?o") ; // Get a result variable by
				// name.
				// Resource r = soln.getResource("?o"); // Get a result variable
				// -
				// must be a resource
				Literal l = soln.getLiteral("?o"); // Get a result variable -
													// must
													// be a literal
				bw.write(l.getLexicalForm());
				bw.newLine();

			}
			fw.close();
			i = 0; // reset file counter
			model.removeAll();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
 
开发者ID:SaudAljaloud,项目名称:RdfLiteralStats,代码行数:31,代码来源:JenaTesting.java

示例11: retriveData

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
	 * Queries factforge endpoint for POIs  based on the coordinates and profile of the user
	 * @param location
	 * @param profile
	 * @param categories
	 * @return
	 */
	public static POIList retriveData(Location location){

		String sparqlquery= "PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> \n"
				+ "PREFIX omgeo: <http://www.ontotext.com/owlim/geo#> \n"
				+ "PREFIX dbpedia: <http://dbpedia.org/resource/> \n"
				+ "PREFIX dbp-ont: <http://dbpedia.org/ontology/> \n"
				+ "PREFIX ff: <http://factforge.net/> \n"
				+ "PREFIX om: <http://www.ontotext.com/owlim/> \n"
				+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
				+ "PREFIX fb: <http://rdf.freebase.com/ns/> \n"
				+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"
				+ "PREFIX prov:<http://www.w3.org/ns/prov#> \n"
				+ "SELECT distinct ?label ?poi ?wikipoi ?lat ?lng ?description ?page ?pic \n "				
				+ "where { \n"
				+ "?poi omgeo:nearby(\""+ String.valueOf(location.getLat())+"\"" + "\"" +String.valueOf(location.getLng())+ "\"" +"\"10km\"). \n"
				+ "?poi rdfs:label ?label . \n"
				+ "?poi prov:wasDerivedFrom ?wikipoi. \n"
				+ "?poi rdfs:comment ?description. \n"
				+ "?poi fb:type.object.type ?type. \n"
				+ "?poi geo-pos:lat ?lat . \n"
				+ "?poi geo-pos:long ?lng .\n"
				+ "FILTER(langMatches(lang(?label), 'EN'))\n"
				+ "OPTIONAL { \n"
				+ "?poi foaf:homepage ?page . \n"
				+ "} \n"
				+ "OPTIONAL { \n"
				+ "?poi foaf:depiction ?pic . \n"
				+ "} \n"
				+ "} \n"
				+ "ORDER BY ASC(?label)  \n";
		
		Query query = QueryFactory.create(sparqlquery);
		long l1 = System.currentTimeMillis();
        QueryExecution qexec = QueryExecutionFactory.sparqlService("http://factforge.net/sparql", query);
        ResultSet results = qexec.execSelect();
        long l2 = System.currentTimeMillis()-l1;
//        logger.error("Time for query "+l2+"\n"+sparqlquery);
        POIList list = new POIList();

        // Parse the retrieved result and create a list of POIs
        while (results.hasNext()) {
            QuerySolution soln = results.nextSolution();
            Resource resource = soln.getResource("poi");
            Resource wikipoi = soln.getResource("wikipoi");
            Literal label = soln.getLiteral("label");
            Literal lat = soln.getLiteral("lat");
            Literal lng = soln.getLiteral("lng");
            POI poi = new POI(resource.toString(), label.getValue().toString(), wikipoi.toString(), Double.valueOf(lat.getValue().toString()), Double.valueOf(lng.getValue().toString()));
            list.add(poi);
        }
        

        qexec.close() ;

        return list;
    }
 
开发者ID:Localizr,项目名称:Localizr,代码行数:64,代码来源:GeoNames.java

示例12: retrieveRecommendedData

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
 * Receives a POI and returns all recommended POIs based on the supertype of the input POI
 * @param resource
 * @return
 */
public static POIList retrieveRecommendedData(String resource){
	
	List<Resource> abstractClasses = new ArrayList<Resource>();
	
	// Get all the supertypes of the defined resource
	abstractClasses= retrieveHierarchyTwo(resource);
	// Get the geolocation information from DBPedia
	Literal geolocation = getGeoLocation(resource);
	String listOfClasses= "";
	int iterator=0;
	
	// Create a list of superclasses that the recommended POIs belong
	for (Resource askedClass:abstractClasses){
		if (iterator>0)
			listOfClasses+="UNION";
		listOfClasses += "{?poi a <"+askedClass+">.}";
		iterator++;
	}
	// Get all POIs of the superclasses in a radius of 25km from the defined location
	String sparqlquery= "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> \n"
			+ "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> \n"
+ "PREFIX foaf:<http://xmlns.com/foaf/0.1/> \n"
+ "PREFIX bif:<bif:>"
+ "select distinct ?poi ?poilabel ?lat ?lon ?wikilink where { \n"
			+listOfClasses
+ "?poi geo:geometry ?poi_geo .\n"
+ "?poi rdfs:label ?poilabel. \n"
+ "?poi geo:lat ?lat. \n"
+ "?poi geo:long ?lon.\n"
+ "?poi foaf:isPrimaryTopicOf ?wikilink.\n"
+ " FILTER(langMatches(lang(?poilabel), 'EN'))"
+ "FILTER (bif:st_intersects(?poi_geo, '"+geolocation.getLexicalForm()+"'^^<http://www.openlinksw.com/schemas/virtrdf#Geometry>, 25) )}";
	Query query = QueryFactory.create(sparqlquery);
 QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
 ResultSet results = qexec.execSelect();
	
 POIList list = new POIList();

    while (results.hasNext()) {
        QuerySolution soln = results.nextSolution();
        Resource poiuri = soln.getResource("poi");
        Resource wikipoi = soln.getResource("wikilink");
        Literal label = soln.getLiteral("poilabel");
        Literal lat = soln.getLiteral("lat");
        Literal lng = soln.getLiteral("lon");
        POI poi = new POI(poiuri.toString(), label.getValue().toString(), wikipoi.toString(), Double.valueOf(lat.getValue().toString()), Double.valueOf(lng.getValue().toString()));
        if (poiuri.toString().equals(resource))
        	continue;
        list.add(poi);
    }
	
    	return list;
}
 
开发者ID:Localizr,项目名称:Localizr,代码行数:59,代码来源:GeoNamesRecommendation.java

示例13: loadDatasetStatistics

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
private void loadDatasetStatistics(OntModel voidModel) {
	Query query = QueryFactory.create(datasetStatisticsQuery);
	QueryExecution qexec = QueryExecutionFactory.create(query, voidModel);

	try {
		ResultSet results = qexec.execSelect();
		for (; results.hasNext();) {
			QuerySolution soln = results.nextSolution();
			OntResource dataset = soln.getResource("Dataset").as(
					OntResource.class);

			Integer triples = (soln.getLiteral("triples") != null) ? soln
					.getLiteral("triples").getInt() : null;
			Integer entities = (soln.getLiteral("entities") != null) ? soln
					.getLiteral("entities").getInt() : null;
			Integer classes = (soln.getLiteral("classes") != null) ? soln
					.getLiteral("entities").getInt() : null;
			Integer properties = (soln.getLiteral("properties") != null) ? soln
					.getLiteral("properties").getInt() : null;
			Integer distinctSubjects = (soln.getLiteral("distinctSubjects") != null) ? soln
					.getLiteral("distinctSubjects").getInt() : null;
			Integer distinctObjects = (soln.getLiteral("distinctObjects") != null) ? soln
					.getLiteral("distinctObjects").getInt() : null;
			Dataset ds = this.getDataset(dataset);
			if (ds != null){
				ds.setTriples(triples);
				ds.setEntities(entities);
				ds.setClasses(classes);
				ds.setProperties(properties);
				ds.setDistinctSubjects(distinctSubjects);
				ds.setDistinctObjects(distinctObjects);
					
				
			}
		}
	} catch (Exception e) {
		Log.debug(this, "Unable to execute classPartitionStatisticsQuery "
				+ query);
	} finally {
		qexec.close();
	}
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.remediator,代码行数:43,代码来源:Datasets.java

示例14: getDouble

import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
public static Double getDouble(String label, QuerySolution querySolution) {
  Literal literal = querySolution.getLiteral(label);
  return literal != null ? literal.getDouble() : null;
}
 
开发者ID:eENVplus,项目名称:tf-exploitation-server,代码行数:5,代码来源:QuerySolutionItemExtractors.java


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