SPARQL query help needed for DBpedia all programming language details

瘦欲@ 提交于 2019-12-01 13:18:04

问题


This is the query I am running to get these details of All programming languages.Every programming language has some influenced other languages or influenced by other language. So there may be many languages in influenced or influenced by. Now the prob is when it is printing all the values of it prints every values separately in rows. You can look into the picture. I want all its influenced or influencedBy programming languages in a single row. Query is below.

SELECT ?pl ?abstract ?influenced ?influencedBy
    WHERE { 
        ?pl dbo:abstract ?abstract .
            ?pl dbo:influenced ?influenced .
            ?pl dbo:influencedBy ?influencedBy .
            ?pl rdf:type dbo:ProgrammingLanguage .
            FILTER (LANG(?abstract) = 'en') .
          }

Screen shot of my result

You can see that This language has two influencedBy values and it is printing them in separate rows.

Website data example


回答1:


As @AKSW said, something like --

SELECT                                                      ?pl 
                                                            ?abstract
       ( group_concat ( ?_influenced; separator="; " )   AS ?influenced )
       ( group_concat ( ?_influencedBy; separator="; " ) AS ?influencedBy ) 
WHERE
  { ?pl  dbo:abstract      ?abstract . 
    ?pl  dbo:influenced    ?_influenced . 
    ?pl  dbo:influencedBy  ?_influencedBy . 
    ?pl  rdf:type          dbo:ProgrammingLanguage . 
    FILTER ( LANG ( ?abstract ) = 'en' ) . 
  } 
GROUP BY ?pl ?abstract

Edit to Add

To get the ?pl_label (and I'm guessing, the ?_influenced_label and ?_influencedBy_label) you now say you want, you will need (and/or want) to tweak things a bit...

SELECT                                                            ?pl 
                                                                  ?pl_label
       ( group_concat ( DISTINCT ?_influenced_label; separator="; " )   AS ?influenced )
       ( group_concat ( DISTINCT ?_influencedBy_label; separator="; " ) AS ?influencedBy ) 
                                                                  ?abstract
WHERE
  { ?pl             rdf:type          dbo:ProgrammingLanguage .
    ?pl             dbo:abstract      ?abstract . 
                    FILTER ( LANG ( ?abstract ) = 'en' ) 
    ?pl             rdfs:label         ?pl_label
                    FILTER ( LANG ( ?pl_label ) = 'en' ) .
    ?pl             dbo:influenced    ?_influenced . 
    ?_influenced    rdfs:label         ?_influenced_label
                    FILTER ( LANG ( ?_influenced_label ) = 'en' ) .
    ?pl             dbo:influencedBy  ?_influencedBy . 
    ?_influencedBy  rdfs:label         ?_influencedBy_label
                    FILTER ( LANG ( ?_influencedBy_label ) = 'en' ) .
          } 
GROUP BY ?pl ?pl_label ?abstract


来源:https://stackoverflow.com/questions/55279825/sparql-query-help-needed-for-dbpedia-all-programming-language-details

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!