В результате общения на форуме с разработчиком Virtuoso возникло желание поглядеть, что бы все это значило и не будет ли оно полезно мне. Итак, смотрим.
Немного ликбеза:
Облако и куб: RDF в аналитической базе данных
Описание языка запросов:
SPARQL
Набор утилит:
Command Line Semantic Web With Redland
В дебиане доступны следующие пакеты: redland-utils (утилита rdfproc), rasqal-utils (утилита roqet) и raptor-utils (утилита rapper). На этих утилитах построен облачный сервис
Triplr — Web Command Line
Запрос из найденных в сети примеров:
$ time roqet -e 'PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?website FROM WHERE { ?person foaf:weblog ?website ; foaf:name ?name . ?website a foaf:Document}'
...
roqet: Query returned 74 results
real 0m1.929s
user 0m0.112s
sys 0m0.012s
$ openload http://planetrdf.com/bloggers.rdf -t|grep Content-Length:
URL: http://planetrdf.com:80/bloggers.rdf
Content-Length: 56645
Теперь попробуем протестировать самостоятельно. Для экспериментов я взял лог веб-сервера, сконвертировав его в файл test.ttl нижеприведенного формата:
@prefix : <http://mobigroup.ru/2011/ttl/example#> .
[] :host "localhost"; :prot "http"; :code 503; :length 12731; :url ""; :type ""; :version "" .
[] :host "localhost"; :prot "https"; :code 503; :length 12731; :url ""; :type "GET"; :version "HTTP/1.1" .
[] :host "localhost"; :prot "https"; :code 302; :length 611; :url "login"; :type "POST"; :version "HTTP/1.1" .
[] :host "localhost"; :prot "https"; :code 200; :length 8006; :url ""; :type "GET"; :version "HTTP/1.1" .
...
$ stat --format=%s test.ttl
8502820
$ wc -l test.ttl
52593 test.ttl
Загружаем в специальное хранилище (используется BerkeleyDB) и выполняем запрос:
$ time rdfproc test.db parse test.ttl turtle -n
rdfproc: Parsing URI file:///tmp/test.ttl with turtle parser
real 1m35.248s
user 0m42.927s
sys 0m7.116s
$ stat --format="%n %s" test.db*
test.db-po2s.db 21569536
test.db-so2p.db 79216640
test.db-sp2o.db 62119936
$ time rdfproc test.db query sparql - 'PREFIX : <http://mobigroup.ru/2011/ttl/example#> SELECT ?code ?url ?length WHERE { ?x :code ?code . FILTER (?code=503) . ?x :url ?url . ?x :length ?length }'>log
rdfproc: Query returned bindings results:
rdfproc: Query returned 1457 results
real 0m13.773s
user 0m13.569s
sys 0m0.132s
А здесь выполняем запрос прямо к файлу:
$ cat test.sparql
PREFIX : <http://mobigroup.ru/2011/ttl/example#>
PREFIX src: <file:>
SELECT ?code ?url ?length
FROM src:test.ttl
WHERE { ?x :code ?code . FILTER (?code=503) . ?x :url ?url . ?x :length ?length }
$ time roqet -qi sparql test.sparql >/dev/null
...подождал полчаса и прервал запрос...
Увы, очень уж тормознуто. Для сравнения, обычный grep:
$ time grep ":code 503;" test.ttl>/dev/null
real 0m0.046s
user 0m0.040s
sys 0m0.008s
$ grep ":code 503;" test.ttl|wc -l
1457
Теперь попробуем виртуозу. Ставим (запрошенный при установке пароль скоро понадобится!):
$ sudo aptitude install virtuoso-opensource
Открываем в браузере ссылку
http://localhost:8890/conductor/ и идем в раздел RDF -> RDF Store Upload, где и грузим наш файл test.ttl ( за 2 минуты 45 секунд). Теперь в разделе RDF->SPARQL выполняем запрос:
PREFIX : <http://mobigroup.ru/2011/ttl/example#>
SELECT ?code ?url ?length
WHERE { ?x :code ?code . FILTER (?code=503) . ?x :url ?url . ?x :length ?length }
Время выполнения не показывает, но результат выдает почти мгновенно.
А вот так с помощью консольной isql-vt стереть нафиг все данные и загрузить новые (см.
DB.DBA.TTLP_MT):
DB.DBA.RDF_GLOBAL_RESET() ;
DB.DBA.TTLP_MT (file_to_string_output ('/tmp/test.ttl'), '', 'http://localhost:8890/DAV/offline');
И пара запросов - на подсчет всех фактов указанного вида и отчет по URL определенного вида:
PREFIX : <http://mobigroup.ru/2011/ttl/haproxy/offline#>
SELECT count(*) as ?count
WHERE { ?x :timestamp ?timestamp }
PREFIX : <http://mobigroup.ru/2011/ttl/haproxy/offline#>
SELECT *
WHERE { ?x :url ?url .
?x :length ?length .
?x :backend ?backend .
?x :session ?session .
FILTER regex(?url, "q=") .
FILTER regex(?url, "/share/") .
}
Ссылки:
Semantic Web
SPARQL — язык запросов к RDF
Знакомимся с RDF и Semantic Web через N3
<> a :RoughGuide; :to :Notation3 .
Primer: Getting into RDF & Semantic Web using N3
W3C Semantic Web Tutorial
A Prototype Knowledge Base for the Life Sciences
О виртуозе:
Extending SPARQL IRI Dereferencing with Virtuoso Sponger Middleware
Sindice, its startup company and 12 billion+ live triples SPARQL endpoint
Геоданные:
OGC Seeks Comment on candidate GeoSPARQL standard
Ресурсы:
RDF-ресурсы (диаграмма кликабельна!)
Currently Alive SPARQL Endpoints
Здесь есть и про bio2rdf
Virtuoso Universal Server AMI for Amazon EC2 Instantiation Guide
What is the Bio2RDF Project?
Страница проекта bio2rdf на sf
Bio2RDF - Demo queries
PubMed : U.S. National Library of Medicine National Institutes of Health