我们正在尝试使用Eclipse IDE中的Protege为我们在Tamil中创建的OWL Ontology执行SparQL查询。代码工作正常但结果似乎没有出现在泰米尔语中。以下是代码和输出。
import java.lang.*;
import java.util.regex.*;
import java.io.*;
import com.hp.hpl.jena.sparql.*;
import com.hp.hpl.jena.*;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.query.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDFS;
import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
import edu.stanford.smi.protegex.owl.model.OWLModel;
public class Sample {
public static void main(String[] args) throws FileNotFoundException, IOException, NullPointerException {
try
{
//opening owl file
InputStream in = new FileInputStream(new File("C:/Users/Sandhya/Desktop/Ontology/newtamil.owl"));
Model model=ModelFactory.createMemModelMaker().createDefaultModel() ;
model.read(in,null);
System.out.println(model);
in.close();
String queryString =
"PREFIX pizza: <http://www.semanticweb.org/ontologies/2013/3/newtamil.owl#> "+
" PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+
"PREFIX owl: <http://www.w3.org/2002/07/owl#> "+
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "+
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+
"SELECT ?subject ?object "+
" WHERE { ?subject rdfs:subClassOf ?object }";
com.hp.hpl.jena.query.Query q = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(q, model);
ResultSet results = qe.execSelect();
while (results.hasNext())
{
System.out.println(results.getResourceModel() );
ResultSetFormatter.out(System.out, results, q);
qe.close();
}
}catch(java.lang.NullPointerException e){ System.out.println(e);}
catch(Exception e){
System.out.println("Query Failed !");
}
}
}
输出: -------------------------------------------------- ------------------------------------ -------------- -------------------------------------------------- -------------------------------------------------- -----------------------------------
|%E0%AE%AA%E0%AE%AA%E0%AF%80%E0%AE%BE%E0%AF%82 | %E0%AF%8D%E0%AE%A4%E0%AF%81%E0%AE%B0%E0%AE%AA |
我们希望这个在泰米尔语中显示。我们还安装了unicode并将输出重定向到文本文件并进行了检查,但它仍然没有给出预期的结果。提前谢谢。
答案 0 :(得分:0)
Jena以UTF-8打印。
看起来数据已经是%编码的。