如何在SPARQL查询中提取片段值(后面的位)

如何在SPARQL查询中提取片段值(后面的位),sparql,jena,Sparql,Jena,我在Eclipse中编写了下面的jena查询,它生成了一个URI和一个与内耳相关的医学疾病的描述 public static void main(String[] args) { String FOAF = "http://http://xmlns.com/foaf/0.1/"; String NS = "http://philshields.altervista.org/owl/_"; String rdf= "http://www.w3

我在Eclipse中编写了下面的jena查询,它生成了一个URI和一个与内耳相关的医学疾病的描述

    public static void main(String[] args) {
        String FOAF = "http://http://xmlns.com/foaf/0.1/";
        String NS = "http://philshields.altervista.org/owl/_";
        String rdf= "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
        String owl= "http://www.w3.org/2002/07/owl#" ;
            String xsd= "http://www.w3.org/2001/XMLSchema#";
                String rdfs= "http://www.w3.org/2000/01/rdf-schema#";
                    String dc= "http://purl.org/dc/elements/1.1/";

        Model model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
        //model =  FileManager.get().loadModel("c:/Ontologies/ICD-10 ontologies/2017_10_26_ICD10_AM_Code Order.owl");
        model =  FileManager.get().loadModel("c:/jena/ICD.owl");
        String resultsAsString;
        String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\r\n" + 
                "PREFIX owl: <http://www.w3.org/2002/07/owl#>\r\n" + 
                "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\r\n" + 
                "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\r\n" + 
                "PREFIX dc: <http://purl.org/dc/elements/1.1/>\r\n" + 
                "SELECT  (str(?subject) AS ?string) ?object\r\n" + 
                "   WHERE {?subject dc:title ?object \r\n" + 
                "FILTER regex(?object,\"inner ear\",\"i\")}\r\n" + 
                "" ;
          Query query = QueryFactory.create(queryString) ;
          try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
                ResultSet results = qexec.execSelect() ;

                for ( ; results.hasNext() ; )
                {

                  //QuerySolution soln = results.nextSolution() ;
                  ResultSetFormatter.out(System.out, results, query) ;

                }

          }
                 }
我试图丢弃所有URI,并保留片段值,即散列后无序的代码号

我尝试使用selectstr?subject作为?string?对象,但它不起作用

SPARQL方式:

JAVA方式:


可能重复为什么不简单地使用STRAFTER?@Phil,也许你也可以使用。谢谢我会尝试上面的建议,我会得到回报。谢谢大家,我阅读了上面的重复文章,意识到我在构建本体时犯了一个错误。我试图提取的ICD代码是一个类。如果你是一台机器,作为一个类和它的URI是可以的,但我需要有ICD代码可供人类使用。我将重新构建本体,并在类(即代码)中放置一个额外的注释。无论如何,我学到了宝贵的一课,那就是“为人类可能想看到的任何东西写注释”。
SELECT  (strafter(str(?subject), "#") as ?fragment) WHERE
{
 #... Something...
}
Resource subject = // Some way to fetch from your query;

String fragment = resource.getlocalName(); // This will return fragment