cosminbasca / surfrdf Goto Github PK
View Code? Open in Web Editor NEWSuRF: a python Object RDF Mapper (ORM).
SuRF: a python Object RDF Mapper (ORM).
here is the code snippet from the federation.py
example
Movie = session.get_class(surf.ns.SURF['Movie'], store = 'local')
m1 = Movie('http://baseuri/m1')
m1.surf_title = "Movie 1"
trying to create a blank node with rdf.BNode but couldn't figure out how. any pointer would be appreciated!
ciao, i'm currently evaluating rdf-related libraries for Python. surf is feature- and documentation-wise my favorite atm. unfortunately it lacks Python 3 support.
if i'd give it a shot and refactored the code to support Python 2 and 3, would that be accepted by the maintainers? if so, would using six
be okay?
When writing to Openlink Virtuoso (07.20.3217) with the current sparql_protocol writer, a 400 bad request is returned with the following error:
Virtuoso 37000 Error SP031: SPARQL compiler: No plain default graph specified in the preamble, but it is needed for triple constructor in DELETE {...} without GRAPH {...}
Examples of the sparql_protocol feature a default_graph
attribute:
store = surf.Store(reader = 'sparql_protocol',
endpoint = 'http://dbpedia.org/sparql',
default_graph = 'http://dbpedia.org')
However, in the code there seems no sign of usage of this attribute, which is needed for triple stores like Virtuoso.
I will create a pull request for the fix.
The code below throws AttributeError: 'ReaderPlugin' object has no attribute 'log'
import surf
from surf.log import setup_logger, set_logger_level
import logging
setup_logger()
set_logger_level(logging.DEBUG)
store = surf.Store(reader="rdflib",
writer="rdflib",
rdflib_store="IOMemory")
session = surf.Session(store)
print "Load RDF data"
store.load_triples(source="http://www.w3.org/People/Berners-Lee/card.rdf")
print len(store)
Person = session.get_class(surf.ns.FOAF["Person"])
all_persons = Person.all()
print "Found %d persons in Tim Berners-Lee's FOAF document" % (len(all_persons))
for person in all_persons:
print person.foaf_name.first
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-fffd51a6eb68> in <module>()
20 all_persons = Person.all()
21
---> 22 print "Found %d persons in Tim Berners-Lee's FOAF document" % (len(all_persons))
23 for person in all_persons:
24 print person.foaf_name.first
/usr/local/lib/python2.7/dist-packages/surf/resource/result_proxy.pyc in __len__(self)
233 """ Return count of resources in this collection. """
234
--> 235 _, get_by_response = self.__execute_get_by()
236 return len(get_by_response)
237
/usr/local/lib/python2.7/dist-packages/surf/resource/result_proxy.pyc in __execute_get_by(self)
214
215 store = self._params['store']
--> 216 self._get_by_response = store.get_by(self.__get_by_args)
217
218 return self.__get_by_args, self._get_by_response
/usr/local/lib/python2.7/dist-packages/surf/store.pyc in get_by(self, params)
148 def get_by(self, params):
149 params["context"] = self.__add_default_context(params.get("context"))
--> 150 return self.reader.get_by(params)
151
152 def execute(self, query):
/usr/local/lib/python2.7/dist-packages/surf/plugin/reader.pyc in get_by(self, params)
165
166 def get_by(self, params):
--> 167 return self._get_by(params)
168
169
/usr/local/lib/python2.7/dist-packages/surf/plugin/query_reader.pyc in _get_by(self, params)
249
250 # Load just subjects and their types
--> 251 table = self._to_table(self._execute(query))
252
253 # Create response structure, preserve order, don't include
/usr/local/lib/python2.7/dist-packages/surf.rdflib-1.0.0_r338-py2.7.egg/surf_rdflib/reader.pyc in _execute(self, query)
78 def _execute(self, query):
79 q_string = unicode(query)
---> 80 self.log.debug(q_string)
81 return self.__graph.query(q_string)
82
AttributeError: 'ReaderPlugin' object has no attribute 'log'
pip install fails - unable to find a suitable SuRF package on PyPi:
pip install --upgrade SuRF
Collecting SuRF
Could not find a version that satisfies the requirement SuRF (from versions: )
No matching distribution found for SuRF
environment: Python 2.7 on Mac OS X 10.9.5 (the error does not seem to be Mac-specific though).
It is not clear to me which licensing is used in this library. Could you please clarify?
Thank you!
graph = store.reader.graph
print graph.serialize(format='n3')
yields something like
@prefix ns2: <http://xmlns.com/foaf/0.1/> .
where ns2
is used instead of the predefined namespace prefix foaf:
. tried different serialization formats with no luck.
is it possible to ask surf to use the predefined namespace prefixes in serialization? thanks!
Background: I'm developing a python library that depends on surf
, called hucitlib
. I use surf
to read and modify resources from a SPARQL endpoint.
Problem: the tests for hucitlib
work fine with surf==1.1.9
, but many of them fail if I upgrade to 1.2.0
.
For example I have a bit that looks like the following:
id = Identifier(id_uri)
id.rdfs_label = Literal(urn)
id.ecrm_P2_has_type = Type(BASE_URI_TYPES % "CTS_URN")
id.save()
return True
and it fails now with this exception
E ValueError: Statement of type [list, tuple] does not
E have all the (s,p,o) members (the length of the
E supplied arguemnt must be at least 3)
The bug seems to be related to surf.plugin.sparql_protocol.writer
and surf.plugin.sparql_protocol.writer
. It is raised whenever (in my tests) the method save()
or is_present()
are called. From what I understand it seems related to some of the underlying SPARQL statements being invalid.
in plugins/surf.rdflib/surf_rdflib/reader.py there is an issue related to the JSON serialization of the query result -- I believe this is due to changes in RDFLib 4.x as opposed to 3.x.
Hi @cosminbasca,
reading the documentation I understood how to change the resource's context using surf
.
But would it be possible to change its URI programmatically? I need to change several thousands of URIs in a triples store, and I'm trying to figure out what's the best way of doing so.
Thanks in advance for your help!
matteo
As far as I can see in the documentation, SuRF is more focused on retrieving RDF resources and map them into Python objects, right @cosminbasca?
I guess the opposite use case is also somehow supported: serialize Python object to RDF. I wonder if there is any documentation or source example covering that aspect. What do the Python classes need to provide?
For instance, for my tries I know they need to provide some kind of logic in the find()
method. I could continue with a fail-and-error approach, but I guess is not very productive...
Thanks in advance.
python 3.7.6 issue error for the Moduel surf.query
class Filter(unicode):
NameError: name 'unicode' is not defined
It will be very helpful, if a work around is provided.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.