日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

本文介紹了SPARQL查詢是否重復我不理解的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用此查詢獲取所有編程語言及其詳細信息。這是我的測試課。我在Java中使用過它,它工作得很好。我面臨的問題是,有一種語言叫做”ML(編程語言)”

它以不同的摘要、不同的影響多次印刷。不僅是ML,還有一些其他語言也在做這件事。我不知道我的查詢中是否有任何問題,或者它是否原樣獲取了準確的數據。

package io.naztech.dbpedia;

import java.io.ByteArrayOutputStream;
import java.util.List;

import org.apache.jena.query.ResultSet;
import org.apache.jena.query.ResultSetFormatter;
import org.apache.jena.sparql.engine.http.QueryEngineHTTP;
import org.junit.BeforeClass;
import org.junit.Test;

import io.naztech.talent.model.PediaTag;

public class testDataFetching {

    @Test
    public void testAllDataFetching() {

        String q =  "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
"+
                    "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
"+
                    "PREFIX dbo: <http://dbpedia.org/ontology/> 
"+
                    "PREFIX dbp: <http://dbpedia.org/property/> 
"+
                    "PREFIX owl: <http://www.w3.org/2002/07/owl#> 
"+
                    "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
" +
                    "PREFIX foaf: <http://xmlns.com/foaf/0.1/> 
" +
                    "PREFIX dc: <http://purl.org/dc/elements/1.1/> 
" +
                    "PREFIX : <http://dbpedia.org/resource/> 
" +
                    "PREFIX dbpedia2: <http://dbpedia.org/property/> 
" +
                    "PREFIX dbpedia: <http://dbpedia.org/> 
" +
                    "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> 
" +

                    "SELECT DISTINCT ?pl ?pl_label ?abstract ?_thumbnail 
" +
                    "( Group_concat ( DISTINCT ?_influenced_label; separator= ", ")   AS ?influenced ) 
" + 
                    "( Group_concat ( DISTINCT ?_influencedBy_label; separator= ", ") AS ?influencedBy ) 
" + 
                    "( group_concat ( DISTINCT ?_sameAs; separator=", " ) AS ?sameAs ) 
" +
                    "( group_concat ( DISTINCT ?_paradigm_label; separator=", " ) AS ?paradigm ) 
" +

                    "WHERE  {
" +

                    "       ?pl rdf:type dbo:ProgrammingLanguage .
" + 

                    "       OPTIONAL { ?pl dbo:abstract ?abstract .
" + 

                    "       FILTER ( LANG ( ?abstract ) = 'en' ) . } 
" + 

                    "       ?pl rdfs:label ?pl_label .
" + 

                    "       FILTER ( LANG ( ?pl_label ) = 'en' ) .
" + 

                    "       OPTIONAL { ?pl dbo:influenced ?_influenced . 
" + 

                    "       ?_influenced rdfs:label ?_influenced_label . 
" + 

                    "       FILTER ( LANG ( ?_influenced_label ) = 'en' ) . } 
" + 

                    "       OPTIONAL { ?pl dbo:influencedBy  ?_influencedBy . 
" + 

                    "       ?_influencedBy  rdfs:label ?_influencedBy_label . 
" + 

                    "       FILTER ( LANG ( ?_influencedBy_label ) = 'en' ) . } 
" +

                    "       OPTIONAL { ?pl owl:sameAs ?_sameAs . } 
" +

                    "       OPTIONAL { ?pl dbp:paradigm ?_paradigm . 
" +

                    "       ?_paradigm rdfs:label ?_paradigm_label . } 
" + 

                    "       OPTIONAL { ?pl dbo:thumbnail ?_thumbnail . } 
" +

                    "       }"+

                    "       GROUP BY ?pl ?pl_label ?abstract ?_thumbnail ?influenced ?influencedBy ?sameAs ?paradigm";

        @SuppressWarnings("resource")
        QueryEngineHTTP queryEngine = new QueryEngineHTTP("http://live.dbpedia.org/sparql", q);
        ResultSet results = queryEngine.execSelect();

        int count = 0;

        while (results.hasNext()) 
        {
            QuerySolution qs =  results.next();
            System.out.println("NAME-->
"+qs.get("pl_label").toString()+"
");

            if(qs.get("influenced") != null)
            {
            System.out.println("INFLUENCED-->
"+qs.get("influenced").toString()+"
"); 
            }
           if(qs.get("influencedBy") != null)
            {
                System.out.println("INFLUENCED BY-->
"+qs.get("influencedBy").toString()+"
"); 
            }
           if(qs.get("abstract") != null)
            {
                System.out.println("ABSTRACT-->
"+qs.get("abstract").toString()+"
");  
            }

            if(qs.get("sameAs") != null)
            {
                System.out.println("SAME AS-->
"+qs.get("sameAs").toString()+"
");  
            }

            if(qs.get("paradigm") != null)
            {
            System.out.println("PARADIGM-->
"+qs.get("paradigm").toString()+"
");  
            }

            if(qs.get("_thumbnail") != null)
            {
                System.out.println("THUMBNAIL-->
"+qs.get("_thumbnail").toString()+"
");  
            }

            System.out.println("
");

            count++;
        }

        System.out.println(count);



    }

}

推薦答案

數據集中有3篇英文摘要,請看DBpedia Live resource。

您可以通過從group by ...部分中刪除?abstract變量來解決此問題,而使用聚合函數(sample, min, max)來獲取任何抽象:

SELECT  ?pl ?pl_label 
        (MIN(?_abstract) AS ?abstract) # <- used MIN here to ensure stable result
        ?_thumbnail 
        (GROUP_CONCAT(DISTINCT ?_influenced_label ; separator='; ') AS ?influenced) 
        (GROUP_CONCAT(DISTINCT ?_influencedBy_label ; separator='; ') AS ?influencedBy) 
        (GROUP_CONCAT(DISTINCT ?_sameAs ; separator=', ') AS ?sameAs) 
        (GROUP_CONCAT(DISTINCT ?_paradigm_label ; separator=', ') AS ?paradigm)
WHERE
  { ?pl  a  dbo:ProgrammingLanguage ;
         rdfs:label  ?pl_label
    FILTER ( lang(?pl_label) = "en" )

    OPTIONAL
      { ?pl  dbo:abstract  ?_abstract
        FILTER ( lang(?_abstract) = "en" )
      }
    OPTIONAL
      { ?pl       dbo:influenced/rdfs:label  ?_influenced_label
        FILTER ( lang(?_influenced_label) = "en" )
      }
    OPTIONAL
      { ?pl       dbo:influencedBy/rdfs:label  ?_influencedBy_label
        FILTER ( lang(?_influencedBy_label) = "en" )
      }
    OPTIONAL
      { ?pl  owl:sameAs  ?_sameAs }
    OPTIONAL
      { ?pl       dbp:paradigm/rdfs:label  ?_paradigm_label
        FILTER ( lang(?_paradigm_label) = "en" )
      }
    OPTIONAL
      { ?pl  dbo:thumbnail  ?_thumbnail }
  }
GROUP BY ?pl ?pl_label ?_thumbnail

更新

我在這里添加@TallTed的評論,他是Virtuoso背后的人之一,比我更了解:

請注意,雖然建議的聚合函數(<[2-3]、MAX
SAMPLE)將獲得值,不能保證
該值將是最新接收到數據集的值。

這篇關于SPARQL查詢是否重復我不理解的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,

分享到:
標簽:SPARQL 我不 查詢 理解 重復
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定