當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。