RDFLib/rdflib — Issue #176: rdflib.store.Memory not working with python 2.7
Author: gjhiggins
Created: 2012-02-20 08:34:27+00:00
State: open

imrantau...@gmail.com, 2011-09-14T20:12:38.000Z

What steps will reproduce the problem?
1.from rdflib.store.Memory import Memory
2.it gives error mentioned below
3.from rdflib.store.Memory import Memory
ImportError: No module named Memory

What is the expected output? What do you see instead?
rdflib.store.Memory should work

What version of the product are you using? On what operating system?
python 2.7

Please provide any additional information below.

Comment 1 by gjhigg...@gmail.com
The supported approach is to use the "IOMemory" store via the plugin mechanism.

Below is shown the reasonably complete example on the wiki's IntroStore page (http://code.google.com/p/rdflib/wiki/IntroStore) that has been straightforwardly adapted to use IOMemory and is ready for copy'n'pasta. HTH

{{{
from rdflib import ConjunctiveGraph as Graph
from rdflib import plugin
from rdflib.store import Store, NO_STORE, VALID_STORE
from rdflib import Namespace
from rdflib import Literal
from rdflib import URIRef

default_graph_uri = "http://rdflib.net/rdfstore"
configString = ""

# Get the mysql plugin. You may have to install the python mysql libraries
store = plugin.get('IOMemory', Store)('rdfstore')

# Open previously created store, or create it if it doesn't exist yet
rt = store.open(configString,create=False)
if rt == NO_STORE:
# There is no underlying MySQL infrastructure, create it
store.open(configString,create=True)
else:
assert rt == VALID_STORE,"There underlying store is corrupted"

# There is a store, use it
graph = Graph(store, identifier = URIRef(default_graph_uri))

print "Triples in graph before add: ", len(graph)

# Now we'll add some triples to the graph & commit the changes
rdflibns = Namespace('http://rdflib.net/test/')
graph.add((rdflibns['pic:1'], rdflibns['name'], Literal('Jane & Bob')))
graph.add((rdflibns['pic:2'], rdflibns['name'], Literal('Squirrel in Tree')))
graph.commit()

print "Triples in graph after add: ", len(graph)

# display the graph in RDF/XML
print graph.serialize()
}}}

Comment 2 by gjhigg...@gmail.com
And there are more examples of using graphs and stores in the API docs:

http://bel-epa.com/rdflibapidocs/rdflib.graph-module.html

Comment 3 by gjhigg...@gmail.com
I'll handle this one.

Comment 4 by imrantau...@gmail.com
Thanks, that works.

Comment 5 by gjhigg...@gmail.com
Ah, (a little later) I see. It's been refactored.

For your original approach you'd need:

from rdflib.plugins.memory import Memory

Sorry it took so long for the penny to drop.

HTH

Graham.

Comment 6 by gjhigg...@gmail.com
No further action required.