Javascript查詢DBpedia的樣本

來源:互聯網
上載者:User

本文介紹如何利用SPARQLWrapper.js來讀取DBpedia的資料,並顯示出來。

本文程式目標:輸入一個英文單詞然後返回WIKI中相關的資訊。

本文主要要解決的問題就是怎樣的SPARQL語句能夠查詢到我們需要的東西。

先看一段簡單的SPARQL查詢語句

PREFIX : <http://aabs.purl.org/music#>SELECT ?instrumentWHERE { :andrew :playsInstrument ?instrument .}

首先定義一個網域名稱空間http://aabs.purl.org/music#。

然後選擇這樣子的instrument變數,他滿足:

主語是http://aabs.purl.org/music#andrew,謂語是http://aabs.purl.org/music#playsInstrument,賓語是該instrument。

bif:contains()

bif:contains()是contains()函數的變種函數,顧名思義是判斷是否包含的函數。

利用這個我們能查詢到我們需要的資料了。

prefix foaf: <http://xmlns.com/foaf/0.1 /> select distinct ?url ?alma ?comment where { ?s foaf:name ?sname . ?sname bif:contains 'China'. ?s foaf:depiction ?url . ?s dbpedia-owl:wikiPageExternalLink ?alma . ?s rdfs:comment ?comment . } limit 10

這段SPARQL語句是查詢包含China的名字的詞條,然後將其圖片的url、homepage的url,以及簡介返回回來。

下面讓我們把整個程式寫完。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.