1
|
package eu.dnetlib.data.mapreduce.hbase.lodImport.utils;
|
2
|
import com.hp.hpl.jena.query.QueryExecution;
|
3
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
4
|
import com.hp.hpl.jena.query.QuerySolution;
|
5
|
import com.hp.hpl.jena.query.ResultSet;
|
6
|
import com.hp.hpl.jena.rdf.model.Model;
|
7
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
8
|
|
9
|
/**
|
10
|
* Method: getCoutryURI
|
11
|
*
|
12
|
* @author Giorgos Alexiou
|
13
|
*
|
14
|
*/
|
15
|
|
16
|
public class MapCountries {
|
17
|
|
18
|
/**
|
19
|
* This Method takes ISO ISO_3166_1 codes for Countries as input and returns the respective URI from dbpedia.org as output.
|
20
|
* For example iso639_3 for Germany is "DE" and the respective URI from dbpedia.org is <http://dbpedia.org/resource/Germany>
|
21
|
*
|
22
|
* @param iso_3166_1_Code
|
23
|
* @return country URI <String>
|
24
|
*/
|
25
|
|
26
|
public static String getCountryURI(String iso_3166_1_Code){
|
27
|
iso_3166_1_Code = iso_3166_1_Code.trim();
|
28
|
Model dbpediaCountries = ModelFactory.createDefaultModel();
|
29
|
dbpediaCountries.read("resources/rdfdata/dbpedia_Countries.rdf", "RDF/XML");
|
30
|
String isoURI = "http://dbpedia.org/resource/ISO_3166-1:"+iso_3166_1_Code;
|
31
|
String query = "PREFIX dbpedia-owl:<http://dbpedia.org/ontology/> select distinct ?s ?r where {<"+isoURI+"> dbpedia-owl:wikiPageRedirects ?s}";
|
32
|
// System.out.println(query);
|
33
|
QueryExecution queryExecution = QueryExecutionFactory.create(query,dbpediaCountries);
|
34
|
ResultSet resultSet = queryExecution.execSelect();
|
35
|
String countryURI="";
|
36
|
while (resultSet.hasNext()) {
|
37
|
QuerySolution qs = resultSet.next();
|
38
|
String uriString = qs.getResource("s").toString().trim();
|
39
|
countryURI=uriString;
|
40
|
}
|
41
|
|
42
|
return countryURI;
|
43
|
|
44
|
}
|
45
|
|
46
|
}
|