Permalink
Browse files

some refactoring and minor fixes

  • Loading branch information...
1 parent 413ee42 commit dc9fe616c7be1b7904f62fc71cb8d617a89c406f @mhausenblas committed Mar 31, 2012
Showing with 50 additions and 22 deletions.
  1. +1 −1 README.md
  2. +22 −0 gk.py
  3. +21 −18 graphkeeper.py
  4. +0 −1 ntriples.py
  5. +6 −2 test/dataset0.nt
View
2 README.md
@@ -23,7 +23,7 @@ To launch GraphKeeper you have to initially `chmod 755 gk-launch.sh` once and se
Then you can try out GraphKeeper and you should see:
- $ python graphkeeper.py
+ $ python gk.py
Set up of GraphKeeper ...
<http://data.example.org/person/tim> dc:publisher "Tim" .
View
22 gk.py
@@ -0,0 +1,22 @@
+"""
+gk - CLI for GraphKeeper
+Michael Hausenblas, DERI
+Public Domain
+Documentation:
+ https://github.com/mhausenblas/graphkeeper
+
+Command line usage:
+ python gk.py <URI> - parses data from URI as N-Triples and loads it into the store
+"""
+from graphkeeper import *
+
+if __name__ == '__main__':
+ if len(sys.argv) == 2:
+ # sys.argv[1]
+ gk = GraphKeeper()
+ print 'Set up of GraphKeeper ...'
+ gk.set_up()
+ # gk.put_ng('/ng', '<http://data.example.org/person/tim> dc:publisher "Tim" .')
+ # (data, stat) = gk.get_ng('/ng-0')
+ # print data
+ else: print __doc__
View
39 graphkeeper.py
@@ -1,14 +1,11 @@
"""
-GraphKeeper
+GraphKeeper, a simple RDF store in ZooKeeper.
Michael Hausenblas, DERI
Public Domain
Documentation:
https://github.com/mhausenblas/graphkeeper
-
-Command line usage:
- python graphkeeper.py <URI> - parses data from URI as N-Triples and loads it into the store
"""
-import zookeeper, threading, ntriples, sys
+import zookeeper, threading, ntriples, urllib, sys
from pprint import pprint
ZOO_OPEN_ACL_UNSAFE = {"perms":0x1f, "scheme":"world", "id" :"anyone"};
@@ -43,6 +40,9 @@ def connection_watcher(handle, type, state, path):
if not self.connected:
raise Exception("Couldn't connect to host -", self.host)
+ # set up the NG2znode look-up table:
+ zookeeper.create(self.handle, '/look-up', 'NOP', [ZOO_OPEN_ACL_UNSAFE], zookeeper.SEQUENCE)
+
def shut_down(self):
if self.connected:
@@ -58,17 +58,20 @@ def get_ng(self, ng):
# adds a named graph and overwrites the content in case it exists already
def put_ng(self, ng, val):
zookeeper.create(self.handle, ng, val, [ZOO_OPEN_ACL_UNSAFE], zookeeper.SEQUENCE)
-
-if __name__ == '__main__':
- if len(sys.argv) == 2:
- gk = GraphKeeper()
- sink = ntriples.parseURI(sys.argv[1])
- # print 'Set up of GraphKeeper ...'
- # gk.set_up()
- #
- # gk.put_ng('/ng', '<http://data.example.org/person/tim> dc:publisher "Tim" .')
- #
- # (data, stat) = gk.get_ng('/ng-0')
- # print data
- else: print __doc__
+ def import_ng(self, uri):
+ pass
+
+class GKSink(object):
+ def __init__(self):
+ self.length = 0
+
+ def triple(self, s, p, o):
+ self.length += 1
+ print(self.length, s, p, o)
+
+if __name__ == '__main__':
+ parser = ntriples.NTriplesParser(sink=GKSink())
+ u = urllib.urlopen('test/dataset0.nt')
+ parser.parse(u)
+ u.close()
View
1 ntriples.py
@@ -225,7 +225,6 @@ def parseURI(uri):
u = urllib.urlopen(uri)
sink = parser.parse(u)
u.close()
- return sink
def main():
import sys
View
8 test/dataset0.nt
@@ -1,6 +1,10 @@
<http://dbpedia.org/resource/Galway> <http://www.w3.org/2000/01/rdf-schema#label> "Galway" .
-<http://dbpedia.org/resource/Galway> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/CitiesInTheRepuBlicOfIreland> .
-<http://dbpedia.org/resource/Galway> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/UniversityTowns> .
+<http://dbpedia.org/resource/Galway> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Place> .
<http://dbpedia.org/resource/Galway> <http://www.georss.org/georss/point> "53.27194444444444 -9.04888888888889"@en .
<http://dbpedia.org/resource/Galway> <http://www.w3.org/2000/01/rdf-schema#comment> "Galway or City of Galway (Cathair na Gaillimhe) is a city in County Galway, Republic of Ireland. It is the fifth largest and the fastest-growing city in Ireland. It is also the third largest city within the Republic (although this is disputed by Limerick) and the only city in the Province of Connacht. Located on the west coast of Ireland, it sits on the River Corrib between Lough Corrib and Galway Bay. The population of Galway's urban area is 75,414 according to the 2011 census." .
<http://dbpedia.org/resource/Galway> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Place> .
+<http://dbpedia.org/resource/Galway> <http://dbpedia.org/ontology/isPartOf> <http://dbpedia.org/resource/Ireland> .
+<http://dbpedia.org/resource/Ireland> <http://www.w3.org/2000/01/rdf-schema#label> "Ireland" .
+<http://dbpedia.org/resource/Ireland> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Place> .
+<http://dbpedia.org/resource/Ireland> <http://www.w3.org/2002/07/owl#sameAs> <http://www4.wiwiss.fu-berlin.de/eurostat/resource/countries/Ireland> .
+<http://dbpedia.org/resource/Ireland> <http://www.w3.org/2000/01/rdf-schema#comment> "Ireland is the third-largest island in Europe and the twentieth-largest island in the world. It lies to the northwest of continental Europe and is surrounded by hundreds of islands and islets. To the east of Ireland is Great Britain, separated from it by the Irish Sea." .

0 comments on commit dc9fe61

Please sign in to comment.