1 |
40723
|
giorgos.al
|
package eu.dnetlib.data.mapreduce.hbase.lodImport.utils;
|
2 |
41002
|
giorgos.al
|
import java.io.InputStream;
|
3 |
|
|
|
4 |
|
|
import org.apache.log4j.Logger;
|
5 |
|
|
|
6 |
40728
|
giorgos.al
|
import com.hp.hpl.jena.query.QueryExecution;
|
7 |
|
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
8 |
|
|
import com.hp.hpl.jena.query.QuerySolution;
|
9 |
|
|
import com.hp.hpl.jena.query.ResultSet;
|
10 |
|
|
import com.hp.hpl.jena.rdf.model.Model;
|
11 |
|
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
12 |
40723
|
giorgos.al
|
|
13 |
|
|
/**
|
14 |
|
|
* Method: getCoutryURI
|
15 |
|
|
*
|
16 |
|
|
* @author Giorgos Alexiou
|
17 |
|
|
*
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
public class MapCountries {
|
21 |
|
|
|
22 |
|
|
/**
|
23 |
|
|
* This Method takes ISO ISO_3166_1 codes for Countries as input and returns the respective URI from dbpedia.org as output.
|
24 |
|
|
* For example iso639_3 for Germany is "DE" and the respective URI from dbpedia.org is <http://dbpedia.org/resource/Germany>
|
25 |
|
|
*
|
26 |
|
|
* @param iso_3166_1_Code
|
27 |
|
|
* @return country URI <String>
|
28 |
|
|
*/
|
29 |
|
|
|
30 |
41007
|
giorgos.al
|
public MapCountries(){
|
31 |
|
|
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
private Logger log = Logger.getLogger(this.getClass());
|
35 |
41019
|
giorgos.al
|
public String getCountryURI(String iso_3166_1_Code){
|
36 |
40723
|
giorgos.al
|
String countryURI="";
|
37 |
41002
|
giorgos.al
|
try{
|
38 |
|
|
iso_3166_1_Code = iso_3166_1_Code.trim();
|
39 |
41057
|
giorgos.al
|
|
40 |
|
|
if(iso_3166_1_Code.equals("UK") || iso_3166_1_Code.equals("GB")) return "http://dbpedia.org/resource/United_Kingdom";
|
41 |
|
|
|
42 |
41002
|
giorgos.al
|
Model dbpediaCountries = ModelFactory.createDefaultModel();
|
43 |
|
|
// URL file = MapCountries.class.getClassLoader().getResource("rdfData/dbpedia_Countries.rdf");
|
44 |
|
|
// InputStream is = new FileInputStream(path);
|
45 |
41008
|
eri.katsar
|
// InputStream is = this.getClass().getResourceAsStream("lodImport/dbpedia_Countries.rdf");
|
46 |
|
|
InputStream is = ClassLoader.getSystemResourceAsStream("eu/dnetlib/data/mapreduce/hbase/lodImport/dbpedia_Countries.rdf");
|
47 |
41002
|
giorgos.al
|
dbpediaCountries.read(is, "RDF/XML");
|
48 |
|
|
String isoURI = "http://dbpedia.org/resource/ISO_3166-1:"+iso_3166_1_Code;
|
49 |
|
|
String query = "PREFIX dbpedia-owl:<http://dbpedia.org/ontology/> select distinct ?s ?r where {<"+isoURI+"> dbpedia-owl:wikiPageRedirects ?s}";
|
50 |
|
|
// System.out.println(query);
|
51 |
|
|
QueryExecution queryExecution = QueryExecutionFactory.create(query,dbpediaCountries);
|
52 |
|
|
ResultSet resultSet = queryExecution.execSelect();
|
53 |
|
|
|
54 |
|
|
while (resultSet.hasNext()) {
|
55 |
|
|
QuerySolution qs = resultSet.next();
|
56 |
|
|
String uriString = qs.getResource("s").toString().trim();
|
57 |
|
|
countryURI=uriString;
|
58 |
|
|
}
|
59 |
|
|
}catch(Exception e){
|
60 |
|
|
|
61 |
|
|
log.error("MapCountries error"+e.toString(),e);
|
62 |
40723
|
giorgos.al
|
}
|
63 |
|
|
return countryURI;
|
64 |
|
|
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
}
|