簡體   English   中英

Sparql:拆分作者和編輯者

[英]Sparql: split authors and editors

終點

http://128.250.202.125:7001/joseki/

到目前為止查詢

PREFIX dc:    <http://purl.org/dc/elements/1.1/>
PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd:   <http://www.w3.org/2001/XMLSchema#>
PREFIX owl:   <http://www.w3.org/2002/07/owl#>
PREFIX fn:    <http://www.w3.org/2005/xpath-functions#>
PREFIX ouext: <http://oracle.com/semtech/jena-adaptor/ext/user-def-function#>
PREFIX oext:  <http://oracle.com/semtech/jena-adaptor/ext/function#>
PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#timeout=10,qid=12345,STRICT_DEFAULT=F,GRAPH_MATCH_UNNAMED=T>
PREFIX fae:   <http://www.findanexpert.unimelb.edu.au/ontology/>
PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>
PREFIX vitro-public: <http://vitro.mannlib.cornell.edu/ns/vitro/public#>
PREFIX vivo:  <http://vivoweb.org/ontology/core#>
PREFIX bibo:  <http://purl.org/ontology/bibo/>
PREFIX foaf:  <http://xmlns.com/foaf/0.1/>

select
    (sample(?title) AS ?publication_title)
    (GROUP_CONCAT(?pubPosi ; SEPARATOR = "|") AS ?publication_position)
    (GROUP_CONCAT(?personLinkDisplay ; SEPARATOR = "|") AS ?personal_link)
where {
    <http://www.findanexpert.unimelb.edu.au/individual/person16492> vivo:authorInAuthorship ?authorship .
    ?authorship vivo:linkedInformationResource ?article .
    ?article vivo:informationResourceInAuthorship ?pubPosi .
    ?pubPosi rdfs:label ?personLabel .

    ?article rdfs:label ?title.

    OPTIONAL {
        ?pubPosi vivo:linkedAuthor ?personLink .
    }

    BIND ( IF( !bound(?personLink), "empty", STR(?personLink)) AS ?personLinkDisplay )
}
group by
    ?article

圖片中的部分結果表

在此處輸入圖片說明

上面查詢的結果說明:

專欄1:“為什么相信科學理論是正確的?” 這是出版物標題

第2欄:

www.findanexpert.....position1Y, "Y" means author. 
"1" means this author is in position 1 in this publication.
"1Y" means this is an author and in position 1.

www.findanexpert.....position2N, "N" means editor. 
"2" means this editor is in position 2 in this publication.
"2N" means this is an editor and in position 2.

“|” 是將作者和編輯分開,但您可以看到它們是混雜的。 我需要在一個專欄中有作者,在另一專欄中有編輯。

第3欄:這表示www.findanexpert ... / publication74143position1Y具有www.findanexpert ... / person16492(個人資料)

www.findanexpert ... / publication74143position1N具有“空”的個人資料。

我不確定如何創建預期的結果:

https://docs.google.com/spreadsheets/d/1UQv41NK0U2PU1tgIeBa__4lQx16v9lKinDtV7eQzMyg/edit?pli=1#gid=0

更新1

我根據約書亞的建議修改了查詢。 距離很近但還沒有

修改后的查詢

PREFIX dc:    <http://purl.org/dc/elements/1.1/>
PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd:   <http://www.w3.org/2001/XMLSchema#>
PREFIX owl:   <http://www.w3.org/2002/07/owl#>
PREFIX fn:    <http://www.w3.org/2005/xpath-functions#>
PREFIX ouext: <http://oracle.com/semtech/jena-adaptor/ext/user-def-function#>
PREFIX oext:  <http://oracle.com/semtech/jena-adaptor/ext/function#>
PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#timeout=15,qid=12345,STRICT_DEFAULT=F,GRAPH_MATCH_UNNAMED=T>
PREFIX fae:   <http://www.findanexpert.unimelb.edu.au/ontology/>
PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>
PREFIX vitro-public: <http://vitro.mannlib.cornell.edu/ns/vitro/public#>
PREFIX vivo:  <http://vivoweb.org/ontology/core#>
PREFIX bibo:  <http://purl.org/ontology/bibo/>
PREFIX foaf:  <http://xmlns.com/foaf/0.1/>

select
    #(sample(?article) as ?article_uri)
    (sample(?title) as ?the_title)

    (group_concat(distinct ?author_posi_uri ; separator='|' ) as ?authors)
  (group_concat(distinct ?the_author_link ; separator='|' ) as ?the_author_links)

  (group_concat(distinct ?editor_posi_uri ; separator='|' ) as ?editors)
  (group_concat(distinct ?the_editor_link ; separator='|' ) as ?the_editor_links)

where { 
    <http://www.findanexpert.unimelb.edu.au/individual/person16492> vivo:authorInAuthorship ?authorship .
    ?authorship vivo:linkedInformationResource ?article .
    ?article rdfs:label ?title.

    # Get authors
    # I can say an ?article should have at least one author.
  ?article vivo:informationResourceInAuthorship ?author_posi_uri .
  filter strends( str(?author_posi_uri), 'Y' ) .

  optional {
    ?author_posi_uri vivo:linkedAuthor ?author_link .
    }
  BIND ( IF( !bound(?author_link), "empty", STR(?author_link)) AS ?the_author_link ) .


  # NOTE: I was hoping to get similar result as 'get authors' above, but it is not.
  # Get editors
  # Not all ?article has editor, that is why I use first 'optional' below.
  # If there is an editor, he/she may not have editor_link (i.e. don't have a profile),
  # So I use 'optional' within another 'optional'
  optional {
    ?article vivo:informationResourceInAuthorship ?editor_posi_uri .
    filter strends( str(?editor_posi_uri), 'N' ) .

    optional {
        ?editor_posi_uri vivo:linkedAuthor ?editor_link .   
    }
    BIND ( IF( !bound(?editor_link), "empty", STR(?editor_link)) AS ?the_editor_link ) .
  }


}
group by ?article ?title

輸出是

在此處輸入圖片說明

圖片說明:

第1列:它是出版物的標題

專欄2:作者

第3列:作者鏈接的個人資料

專欄4:編輯

第5欄:編輯器鏈接的配置文件。 第5欄無法正常工作。 我期望與第3列類似。

更新2

下圖顯示有3位作者,但在'the_author_links'列中僅顯示2個項目,因為'distinct'關鍵字實際上刪除了所有重復的'empty'

the'distinct' keyword is collided with this
BIND ( IF( !bound(?author_link), "empty", STR(?author_link)) AS ?the_author_link )

在此處輸入圖片說明

有辦法解決嗎?

我們無權訪問您的數據,因此我們無法真正為您提供確切的查詢,但我認為我們可以非常接近。 讓我們從一個簡化的版本開始,該版本不具有作者和作者鏈接以及編輯器和編輯器鏈接,而僅具有hasAuthor屬性,並且該屬性的值分別是作者和編輯者的以Y或N結尾的URI。 然后我們可以得到一些像這樣的數據:

@prefix : <urn:ex:>.

:article2 :hasTitle "Some title" ;
          :hasAuthor :person1Y, :person2Y, :person3N, :person4N .

然后,我們可以編寫一個查詢,以檢索文章及其標題以及hasAuthor屬性的值(可選)。 如果hasAuthor屬性的值以Y結尾,則將其綁定到變量?author,如果變量以N結束,則將其綁定到?editor。如果它不以任何一個結尾,則我們不對它進行任何操作它。 我將在最后顯示查詢和結果,但這是到目前為止的模式:

  ?article :hasTitle ?title .

  # Find "authors" with URIs ending in 'Y' (authors)
  optional { 
    ?article :hasAuthor ?author .
    filter strends( str(?author), 'Y' )
  }

  # Find "authors" with URIs ending in 'N' (editors)
  optional { 
    ?article :hasAuthor ?editor .
    filter strends( str(?editor), 'N' )
  }

現在,我們如何將這些價值觀完全融合在一起。 首先,我們要按文章和標題進行分組。 然后,每個組都有一個唯一的文章和標題,以及作者和編輯者值的一些集合。 我們希望將由?分隔的?author的所有不同值連接到變量?authors中,並類似地將?editor合並為?edits。 因此,我們最終得到以下查詢和結果:

prefix : <urn:ex:>

select ?title
       (group_concat(distinct ?author ; separator='|' ) as ?authors)
       (group_concat(distinct ?editor ; separator='|' ) as ?editors)
where {
  ?article :hasAuthor :person1Y ;
           :hasTitle ?title .

  # Find "authors" with URIs ending in 'Y' (authors)
  optional { 
    ?article :hasAuthor ?author .
    filter strends( str(?author), 'Y' )
  }

  # Find "authors" with URIs ending in 'N' (editors)
  optional { 
    ?article :hasAuthor ?editor .
    filter strends( str(?editor), 'N' )
  }
}
group by ?article ?title
----------------------------------------------------------------------------------------
| title        | authors                           | editors                           |
========================================================================================
| "Some title" | "urn:ex:person2Y|urn:ex:person1Y" | "urn:ex:person4N|urn:ex:person3N" |
----------------------------------------------------------------------------------------

現在,我們可以使數據更加真實,並為作者和編輯者提供更多信息(例如名稱)。 這樣我們得到:

@prefix : <urn:ex:>.

:article2 :hasTitle "Some title" ;
          :hasAuthor :person1Y, :person2Y, :person3N, :person4N .

:person1Y :hasName "p1" .
:person2Y :hasName "p2" .
:person3N :hasName "p3" .
:person4N :hasName "p4" .

我們也可以擴展可選塊以獲取名稱,然后添加其他組串聯:

prefix : <urn:ex:>

select ?title
       (group_concat(distinct ?author ; separator='|' ) as ?authors)
       (group_concat(distinct ?aname  ; separator='|' ) as ?author_names)
       (group_concat(distinct ?editor ; separator='|' ) as ?editors)
       (group_concat(distinct ?ename  ; separator='|' ) as ?editor_names)
where {
  ?article :hasTitle ?title .

  # Find "authors" with URIs ending in 'Y' (authors)
  optional { 
    ?article :hasAuthor ?author .
    filter strends( str(?author), 'Y' )
    ?author :hasName ?aname .
  }

  # Find "authors" with URIs ending in 'N' (editors)
  optional { 
    ?article :hasAuthor ?editor .
    filter strends( str(?editor), 'N' )
    ?editor :hasName ?ename .
  }
}
group by ?article ?title
----------------------------------------------------------------------------------------------------------------------
| title        | authors                           | author_names | editors                           | editor_names |
======================================================================================================================
| "Some title" | "urn:ex:person2Y|urn:ex:person1Y" | "p2|p1"      | "urn:ex:person4N|urn:ex:person3N" | "p4|p3"      |
----------------------------------------------------------------------------------------------------------------------

現在,這些結果具有相同順序的作者和作者名稱(以及編輯者和編輯者名稱)。 您可能會發現大多數SPARQL引擎都會得到該結果,但實際上並不能保證。 也就是說,您可以擁有:

  • 作者:“ urn:ex:person2Y | urn:ex:person1Y”
  • author_names:“ p1 | p2”

每個字段中作者的順序不同。 不幸的是,在SPARQL 1.1中您無法做任何事情來確保它們以相同的順序結束。 我想,您可以使用字符串操作來執行某些操作,即生成形式為“:person1 / p1 | :: person2 / p2”的字符串,然后進行一些替換以獲取“:person1 | :: person2”和“ p1 | p2” “ 從中。 這樣可以保留訂單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM