| 1 | http://4store.org/trac/wiki/Documentation |
| 2 | |
| 3 | = Installation = |
| 4 | |
| 5 | For Mac OS X with MacPorts user. |
| 6 | {{{ |
| 7 | git clone git@github.com:nakao/4store.git |
| 8 | cd 4store |
| 9 | ./configure |
| 10 | }}} |
| 11 | |
| 12 | {{{ |
| 13 | port install pkg-config |
| 14 | port install raptor |
| 15 | port install rasqal |
| 16 | port install glib2 |
| 17 | port install libxml2 |
| 18 | port install pcre |
| 19 | port install ncurses |
| 20 | port instal readline |
| 21 | port install zlib |
| 22 | }}} |
| 23 | +universal variant configuration may be useful. |
| 24 | Install |
| 25 | {{{ |
| 26 | ./configure |
| 27 | make |
| 28 | make test |
| 29 | }}} |
| 30 | |
| 31 | Install as a Mac .dmg package |
| 32 | {{{ |
| 33 | make macdmg |
| 34 | }}} |
| 35 | |
| 36 | or |
| 37 | |
| 38 | {{{ |
| 39 | sudo make install |
| 40 | }}} |
| 41 | |
| 42 | |
| 43 | = Usage = |
| 44 | 4store Commands |
| 45 | {{{ |
| 46 | $ ls /Applications/4store.app/Contents/MacOS/bin/ |
| 47 | 4s-backend* 4s-cluster-create* 4s-httpd* |
| 48 | 4s-backend-copy* 4s-cluster-destroy* 4s-import* |
| 49 | 4s-backend-destroy* 4s-cluster-file-backup* 4s-info* |
| 50 | 4s-backend-info* 4s-cluster-info* 4s-query* |
| 51 | 4s-backend-passwd* 4s-cluster-replication-disable* 4s-resolve* |
| 52 | 4s-backend-setup* 4s-cluster-start* 4s-restore* |
| 53 | 4s-bind* 4s-cluster-stop* 4s-reverse-bind* |
| 54 | 4s-cluster-cache* 4s-delete-model* 4s-size* |
| 55 | 4s-cluster-copy* 4s-dump* 4s-update* |
| 56 | }}} |
| 57 | |
| 58 | |
| 59 | To setup a knowledge base (named demo) by 4s-backend-setup |
| 60 | http://4store.org/trac/wiki/CreateDatabase |
| 61 | |
| 62 | |
| 63 | {{{ |
| 64 | $ 4s-backend-setup demo |
| 65 | 4store[39388]: backend-setup.c:176 erased files for KB demo |
| 66 | 4store[39388]: backend-setup.c:301 created RDF metadata for KB demo |
| 67 | }}} |
| 68 | |
| 69 | You can find the database files at /var/lib/4store/demo . |
| 70 | |
| 71 | |
| 72 | |
| 73 | To boot a backend process by 4s-backend |
| 74 | {{{ |
| 75 | 4s-backend demo |
| 76 | }}} |
| 77 | |
| 78 | |
| 79 | |
| 80 | To import triples by 4s-import |
| 81 | http://4store.org/trac/wiki/ImportData |
| 82 | |
| 83 | {{{ |
| 84 | curl -O |
| 85 | $ 4s-import -v demo data/tiger/tiger_features.rdf |
| 86 | removing old data |
| 87 | Reading <file:///Users/nakao/Applications/4store/4store/data/tiger/tiger_features.rdf>; |
| 88 | Pass 1, processed 748 triples (748) |
| 89 | Pass 2, processed 748 triples, 90250 triples/s |
| 90 | Updating index |
| 91 | Index update took 1.469478 seconds |
| 92 | Imported 748 triples, average 505 triples/s |
| 93 | }}} |
| 94 | |
| 95 | |
| 96 | 4s-query is a interactive query shell |
| 97 | http://4store.org/trac/wiki/Query |
| 98 | |
| 99 | {{{ |
| 100 | $ 4s-query demo4store> SELECT * WHERE {?s ?p ?o} |
| 101 | #EOQ |
| 102 | ?s ?p ?o |
| 103 | <http://www.census.gov/tiger/2002/CFCC/D85>; <http://www.w3.org/2000/01/rdf-schema#subClassOf>; <http://www.census.gov/tiger/2002/CFCC/D8>; |
| 104 | <http://www.census.gov/tiger/2002/CFCC/F40>; <http://www.w3.org/2000/01/rdf-schema#subClassOf>; <http://www.census.gov/tiger/2002/CFCC/F4>; |
| 105 | <http://www.census.gov/tiger/2002/CFCC/E0>; <http://www.w3.org/2000/01/rdf-schema#subClassOf>; <http://www.census.gov/tiger/2002/CFCC/E>; |
| 106 | }}} |
| 107 | Ctrl+D |
| 108 | |
| 109 | To query in one-liner |
| 110 | {{{ |
| 111 | $ 4s-query demo 'SELECT * WHERE { ?s ?p ?o } LIMIT 1' |
| 112 | <?xml version="1.0"?> |
| 113 | <sparql xmlns="http://www.w3.org/2005/sparql-results#">; |
| 114 | <head> |
| 115 | <variable name="s"/> |
| 116 | <variable name="p"/> |
| 117 | <variable name="o"/> |
| 118 | </head> |
| 119 | <results> |
| 120 | <result> |
| 121 | <binding name="s"><uri>http://www.census.gov/tiger/2002/CFCC/D85</uri></binding>; |
| 122 | <binding name="p"><uri>http://www.w3.org/2000/01/rdf-schema#subClassOf</uri></binding>; |
| 123 | <binding name="o"><uri>http://www.census.gov/tiger/2002/CFCC/D8</uri></binding>; |
| 124 | </result> |
| 125 | </results> |
| 126 | </sparql> |
| 127 | }}} |
| 128 | |
| 129 | in JSON format |
| 130 | {{{ |
| 131 | $ 4s-query -f json demo 'SELECT * WHERE { ?s ?p ?o } LIMIT 1' |
| 132 | {"head":{"vars":["s","p","o"]}, |
| 133 | "results": { |
| 134 | "bindings":[ |
| 135 | {"s":{"type":"uri","value":"http://www.census.gov/tiger/2002/CFCC/D85";}, |
| 136 | "p":{"type":"uri","value":"http://www.w3.org/2000/01/rdf-schema#subClassOf";}, |
| 137 | "o":{"type":"uri","value":"http://www.census.gov/tiger/2002/CFCC/D8";}} |
| 138 | ] |
| 139 | }} |
| 140 | }}} |
| 141 | [http://www.w3.org/TR/rdf-sparql-json-res/ Serializing SPARQL Query Results in JSON] |
| 142 | |
| 143 | in SPARQL-RESULTS format |
| 144 | |
| 145 | {{{ |
| 146 | $ 4s-query -f sparql demo 'SELECT * WHERE { ?s ?p ?o } LIMIT 1' |
| 147 | <?xml version="1.0"?> |
| 148 | <sparql xmlns="http://www.w3.org/2005/sparql-results#">; |
| 149 | <head> |
| 150 | <variable name="s"/> |
| 151 | <variable name="p"/> |
| 152 | <variable name="o"/> |
| 153 | </head> |
| 154 | <results> |
| 155 | <result> |
| 156 | <binding name="s"><uri>http://www.census.gov/tiger/2002/CFCC/D85</uri></binding>; |
| 157 | <binding name="p"><uri>http://www.w3.org/2000/01/rdf-schema#subClassOf</uri></binding>; |
| 158 | <binding name="o"><uri>http://www.census.gov/tiger/2002/CFCC/D8</uri></binding>; |
| 159 | </result> |
| 160 | </results> |
| 161 | </sparql> |
| 162 | }}} |
| 163 | [http://www.w3.org/TR/rdf-sparql-XMLres/ SPARQL Query Results XML Format] |
| 164 | |
| 165 | |
| 166 | in a text format |
| 167 | |
| 168 | {{{ |
| 169 | $ 4s-query -f text demo 'SELECT * WHERE { ?s ?p ?o } LIMIT 1' |
| 170 | ?s ?p ?o |
| 171 | <http://www.census.gov/tiger/2002/CFCC/D85>; <http://www.w3.org/2000/01/rdf-schema#subClassOf>; <http://www.census.gov/tiger/2002/CFCC/D8>; |
| 172 | }}} |
| 173 | |
| 174 | in RDF test case format (Turtle) |
| 175 | |
| 176 | {{{ |
| 177 | $ 4s-query -f testcase demo 'SELECT * WHERE { ?s ?p ?o } LIMIT 1' |
| 178 | @prefix rs: <http://www.w3.org/2001/sw/DataAccess/tests/result-set#>; . |
| 179 | @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>; . |
| 180 | @prefix xsd: <http://www.w3.org/2001/XMLSchema#>; . |
| 181 | |
| 182 | [] rdf:type rs:ResultSet ; |
| 183 | rs:resultVariable "s", "p", "o" ; |
| 184 | rs:solution [ |
| 185 | rs:binding [ rs:variable "s" ; |
| 186 | rs:value <http://www.census.gov/tiger/2002/CFCC/D85> ] ; |
| 187 | rs:binding [ rs:variable "p" ; |
| 188 | rs:value <http://www.w3.org/2000/01/rdf-schema#subClassOf> ] ; |
| 189 | rs:binding [ rs:variable "o" ; |
| 190 | rs:value <http://www.census.gov/tiger/2002/CFCC/D8> ] |
| 191 | ] . |
| 192 | }}} |
| 193 | [http://www.w3.org/TeamSubmission/turtle/ Turtle] |
| 194 | |
| 195 | |
| 196 | 4s-httpd for a SPARQL endpoint |
| 197 | {{{ |
| 198 | $ 4s-httpd -p 8000 demo |
| 199 | }}} |
| 200 | |
| 201 | |
| 202 | [[Image(http://img.skitch.com/20100106-ey6gcjsu42qsege2gimq316ia6.jpg)]] |
| 203 | |
| 204 | [[Image(http://img.skitch.com/20100106-nsq5ir2j1c6ynbkmif43t5a9p8.jpg)]] |
| 205 | |
| 206 | [[Image(http://img.skitch.com/20100106-cb9dq16jare8b33q82exaq12c.jpg)]] |
| 207 | |
| 208 | [[Image(http://img.skitch.com/20100106-x8hfwfdjt3xkexyn9nwcg346nh.jpg)]] |
| 209 | |
| 210 | [[Image(http://img.skitch.com/20100106-8g2w2r4tsycy8sdwrnxa6966hp.jpg)]] |
| 211 | |
| 212 | |
| 213 | |
| 214 | RESTful interface |
| 215 | |
| 216 | PUT |
| 217 | {{{ |
| 218 | $ curl -T file.rdf http://localhost:8000/sparql/file.rdf |
| 219 | }}} |
| 220 | |
| 221 | DELETE |
| 222 | {{{ |
| 223 | $ curl -X DELETE http://localhost:8000/sparql/file.rdf |
| 224 | }}} |
| 225 | Note: http://4store.org/trac/wiki/TODO |
| 226 | |
| 227 | |
| 228 | Connecting from script language |
| 229 | |
| 230 | http://4store.org/trac/wiki/ClientLibraries |
| 231 | available php, python, ruby and Java (no Perl) |
| 232 | |
| 233 | To install the ruby client |
| 234 | {{{ |
| 235 | $ gem build 4store-ruby.gemspec |
| 236 | WARNING: no rubyforge_project specified |
| 237 | Successfully built RubyGem |
| 238 | Name: 4store-ruby |
| 239 | Version: 0.0.3 |
| 240 | File: 4store-ruby-0.0.3.gem |
| 241 | $ sudo gem install 4store-ruby-0.0.3.gem |
| 242 | }}} |
| 243 | |
| 244 | Usage |
| 245 | {{{ |
| 246 | >> require 'four_store/store' |
| 247 | => true |
| 248 | >> FourStore |
| 249 | => FourStore |
| 250 | >> FourStore::Store |
| 251 | => FourStore::Store |
| 252 | >> ep = FourStore::Store.new("http://localhost:8000/sparql/";) |
| 253 | => #<FourStore::Store:0x101763890 @endpoint=#<URI::HTTP:0x101763548 URL:http://localhost:8000/sparql/>>; |
| 254 | >> res = ep.select("SELECT * WHERE { ?s ?p ?o } LIMIT 10"); |
| 255 | ?> " |
| 256 | " |
| 257 | => "\n" |
| 258 | >> require 'pp' |
| 259 | => true |
| 260 | >> pp res |
| 261 | [{"o"=>"http://www.census.gov/tiger/2002/CFCC/D8";, |
| 262 | "p"=>"http://www.w3.org/2000/01/rdf-schema#subClassOf";, |
| 263 | "s"=>"http://www.census.gov/tiger/2002/CFCC/D85";}, |
| 264 | {"o"=>"http://www.census.gov/tiger/2002/CFCC/F4";, |
| 265 | "p"=>"http://www.w3.org/2000/01/rdf-schema#subClassOf";, |
| 266 | "s"=>"http://www.census.gov/tiger/2002/CFCC/F40";}, |
| 267 | {"o"=>"http://www.census.gov/tiger/2002/CFCC/E";, |
| 268 | "p"=>"http://www.w3.org/2000/01/rdf-schema#subClassOf";, |
| 269 | "s"=>"http://www.census.gov/tiger/2002/CFCC/E0";}, |
| 270 | {"o"=>"http://www.census.gov/tiger/2002/CFCC/B";, |
| 271 | "p"=>"http://www.w3.org/2000/01/rdf-schema#subClassOf";, |
| 272 | "s"=>"http://www.census.gov/tiger/2002/CFCC/B4";}, |
| 273 | {"o"=>"http://www.census.gov/tiger/2002/CFCC/D2";, |
| 274 | "p"=>"http://www.w3.org/2000/01/rdf-schema#subClassOf";, |
| 275 | "s"=>"http://www.census.gov/tiger/2002/CFCC/D27";}, |
| 276 | {"o"=>"http://www.census.gov/tiger/2002/CFCC/A";, |
| 277 | "p"=>"http://www.w3.org/2000/01/rdf-schema#subClassOf";, |
| 278 | "s"=>"http://www.census.gov/tiger/2002/CFCC/A5";}, |
| 279 | {"o"=>"http://www.census.gov/tiger/2002/CFCC/A2";, |
| 280 | "p"=>"http://www.w3.org/2000/01/rdf-schema#subClassOf";, |
| 281 | "s"=>"http://www.census.gov/tiger/2002/CFCC/A21";}, |
| 282 | {"o"=>"http://www.census.gov/tiger/2002/CFCC/H7";, |
| 283 | "p"=>"http://www.w3.org/2000/01/rdf-schema#subClassOf";, |
| 284 | "s"=>"http://www.census.gov/tiger/2002/CFCC/H70";}, |
| 285 | {"o"=>"http://www.census.gov/tiger/2002/CFCC/B5";, |
| 286 | "p"=>"http://www.w3.org/2000/01/rdf-schema#subClassOf";, |
| 287 | "s"=>"http://www.census.gov/tiger/2002/CFCC/B52";}, |
| 288 | {"o"=>"http://www.census.gov/tiger/2002/CFCC/D4";, |
| 289 | "p"=>"http://www.w3.org/2000/01/rdf-schema#subClassOf";, |
| 290 | "s"=>"http://www.census.gov/tiger/2002/CFCC/D43";}] |
| 291 | => nil |
| 292 | }}} |
| 293 | |
| 294 | Methods in FourStore::Store class. |
| 295 | {{{ |
| 296 | >> FourStore::Store.instance_methods - Object.methods |
| 297 | => ["delete", "add", "set", "select", "load"] |
| 298 | }}} |