-1
public class MainClass {

public static void main(String[] args) {
    MainClass c = new MainClass();
    c.getType("m.012x34");
    System.out.println("---------------");
    MainClass c1 = new MainClass();
    c1.getType("m.012x34");
}

public String getType(String mid){      
String Type = null; 
try{
    InputStream inputStream = null;
    Resource resource = null;
    File automake_triples = new File(".\\automake_triples.ttl");

    ArrayList<String> products = new ArrayList<String>();
    InputStream in = new FileInputStream(automake_triples);

    final Model model = ModelFactory.createMemModelMaker().createDefaultModel();
        model.read(in ,null , "Turtle"); 
    in.close();

    String queryString = 
        "SELECT ?type" +
        " WHERE {" +
        " ?mid <type.type> ?type ." +
        " }";

    final Query query = QueryFactory.create(queryString);
    final ParameterizedSparqlString pss = new ParameterizedSparqlString(queryString);
    final QuerySolutionMap map = new QuerySolutionMap();
    final Resource res_mid = model.getResource(mid);    
    map.add("mid", (RDFNode) res_mid);
    pss.setParams(map);    

    System.out.println(pss);
    QueryExecution qe = QueryExecutionFactory.create(pss.toString(), model);            
        ResultSetFormatter.out( QueryExecutionFactory.create( pss.toString(), model ).execSelect() );

    qe.close();
    }catch(Exception ex){
    System.out.println(ex);
    ex.printStackTrace();
    }       
    return Type;
 }

}

Sample Input (In the ttl file):

<m.012x34>
      <automotive.company.make_s> <m.0h5wslk> ;
      <type.object.name> "Jaguar" ;
      <type.type> "automotive.company" .

<m.0ywc>
      <automotive.company.make_s> <m.0h5wtfh> , <m.06m97r> ;
      <type.object.name> "Aston Martin" ;
      <type.type> "automotive.company" .

Sample Output:

SELECT ?type WHERE { <m.012x34> <type.type> ?type .} 
------------------------ 
| type | 
======================== 
| "automotive.company" | 
------------------------
--------------- 
SELECT ?type WHERE 
{ <m.012x34> <type.type> ?type .} 
-------- 
| type | 
======== 
--------

このコードが実行されると、初めて適切な値が返されます。getTypeただし、リクエストが同じ値であっても、2 回目に呼び出されたときに値は返されません。私が見つけられないいくつかの問題があるようです。何が問題ですか?

4

1 に答える 1