Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated #1527

Merged
merged 2 commits into from Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/intro_to_graphs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ For example:

.. code-block:: python

g.load("some_foaf.ttl")
g.parse("some_foaf.ttl")
# find all subjects (s) of type (rdf:type) person (foaf:Person)
for s, p, o in g.triples((None, RDF.type, FOAF.Person)):
print(f"{s} is a person")
Expand Down
2 changes: 1 addition & 1 deletion docs/intro_to_sparql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ initial bindings:
)

g = rdflib.Graph()
g.load("foaf.rdf")
g.parse("foaf.rdf")

tim = rdflib.URIRef("http://www.w3.org/People/Berners-Lee/card#i")

Expand Down
2 changes: 1 addition & 1 deletion examples/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
if __name__ == "__main__":

graph = Graph()
graph.load("foaf.n3", format="n3")
graph.parse("foaf.n3", format="n3")

for person in graph[: RDF.type : FOAF.Person]:
friends = list(graph[person : FOAF.knows * "+" / FOAF.name])
Expand Down
2 changes: 1 addition & 1 deletion examples/sparql_query_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if __name__ == "__main__":

g = rdflib.Graph()
g.load("foaf.n3", format="n3")
g.parse("foaf.n3", format="n3")

# The QueryProcessor knows the FOAF prefix from the graph
# which in turn knows it from reading the N3 RDF file
Expand Down
2 changes: 1 addition & 1 deletion examples/sparql_update_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if __name__ == "__main__":

g = rdflib.Graph()
g.load("foaf.n3", format="n3")
g.parse("foaf.n3", format="n3")

print(f"Initially there are {len(g)} triples in the graph")

Expand Down
4 changes: 2 additions & 2 deletions rdflib/extras/cmdlineutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main(target, _help=_help, options="", stdin=True):
start = time.time()
if len(files) == 0 and stdin:
sys.stderr.write("Reading from stdin as %s..." % f)
g.load(sys.stdin, format=f)
g.parse(sys.stdin, format=f)
sys.stderr.write("[done]\n")
else:
size = 0
Expand All @@ -58,7 +58,7 @@ def main(target, _help=_help, options="", stdin=True):
f = guess_format(x)
start1 = time.time()
sys.stderr.write("Loading %s as %s... " % (x, f))
g.load(x, format=f)
g.parse(x, format=f)
sys.stderr.write(
"done.\t(%d triples\t%.2f seconds)\n"
% (len(g) - size, time.time() - start1)
Expand Down
135 changes: 0 additions & 135 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,117 +766,6 @@ def value(
pass
return retval

def label(self, subject, default=""):
"""Query for the RDFS.label of the subject

Return default if no label exists or any label if multiple exist.
"""
warn(
DeprecationWarning(
"graph.label() is deprecated and will be removed in rdflib 6.0.0."
)
)
if subject is None:
return default
return self.value(subject, namespace.RDFS.label, default=default, any=True)

def preferredLabel(
self,
subject,
lang=None,
default=None,
labelProperties=(namespace.SKOS.prefLabel, namespace.RDFS.label),
):
"""
Find the preferred label for subject.

By default prefers skos:prefLabels over rdfs:labels. In case at least
one prefLabel is found returns those, else returns labels. In case a
language string (e.g., "en", "de" or even "" for no lang-tagged
literals) is given, only such labels will be considered.

Return a list of (labelProp, label) pairs, where labelProp is either
skos:prefLabel or rdfs:label.

>>> from rdflib import ConjunctiveGraph, URIRef, Literal, namespace
>>> from pprint import pprint
>>> g = ConjunctiveGraph()
>>> u = URIRef("http://example.com/foo")
>>> g.add([u, namespace.RDFS.label, Literal("foo")]) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.ConjunctiveGraph'>)>
>>> g.add([u, namespace.RDFS.label, Literal("bar")]) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.ConjunctiveGraph'>)>
>>> pprint(sorted(g.preferredLabel(u)))
[(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'),
rdflib.term.Literal('bar')),
(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'),
rdflib.term.Literal('foo'))]
>>> g.add([u, namespace.SKOS.prefLabel, Literal("bla")]) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.ConjunctiveGraph'>)>
>>> pprint(g.preferredLabel(u))
[(rdflib.term.URIRef('http://www.w3.org/2004/02/skos/core#prefLabel'),
rdflib.term.Literal('bla'))]
>>> g.add([u, namespace.SKOS.prefLabel, Literal("blubb", lang="en")]) # doctest: +ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.ConjunctiveGraph'>)>
>>> sorted(g.preferredLabel(u)) #doctest: +NORMALIZE_WHITESPACE
[(rdflib.term.URIRef('http://www.w3.org/2004/02/skos/core#prefLabel'),
rdflib.term.Literal('bla')),
(rdflib.term.URIRef('http://www.w3.org/2004/02/skos/core#prefLabel'),
rdflib.term.Literal('blubb', lang='en'))]
>>> g.preferredLabel(u, lang="") #doctest: +NORMALIZE_WHITESPACE
[(rdflib.term.URIRef('http://www.w3.org/2004/02/skos/core#prefLabel'),
rdflib.term.Literal('bla'))]
>>> pprint(g.preferredLabel(u, lang="en"))
[(rdflib.term.URIRef('http://www.w3.org/2004/02/skos/core#prefLabel'),
rdflib.term.Literal('blubb', lang='en'))]
"""
warn(
DeprecationWarning(
"graph.preferredLabel() is deprecated and will be removed in rdflib 6.0.0."
)
)
if default is None:
default = []

# setup the language filtering
if lang is not None:
if lang == "": # we only want not language-tagged literals

def langfilter(l_):
return l_.language is None

else:

def langfilter(l_):
return l_.language == lang

else: # we don't care about language tags

def langfilter(l_):
return True

for labelProp in labelProperties:
labels = list(filter(langfilter, self.objects(subject, labelProp)))
if len(labels) == 0:
continue
else:
return [(labelProp, l_) for l_ in labels]
return default

def comment(self, subject, default=""):
"""Query for the RDFS.comment of the subject

Return default if no comment exists
"""
warn(
DeprecationWarning(
"graph.comment() is deprecated and will be removed in rdflib 6.0.0."
)
)
if subject is None:
return default
return self.value(subject, namespace.RDFS.comment, default=default, any=True)

def items(self, list):
"""Generator over all items in the resource specified by list

Expand Down Expand Up @@ -981,21 +870,6 @@ def transitive_subjects(self, predicate, object, remember=None):
for s in self.transitive_subjects(predicate, subject, remember):
yield s

def seq(self, subject):
"""Check if subject is an rdf:Seq

If yes, it returns a Seq class instance, None otherwise.
"""
warn(
DeprecationWarning(
"graph.seq() is deprecated and will be removed in rdflib 6.0.0."
)
)
if (subject, RDF.type, RDF.Seq) in self:
return Seq(self, subject)
else:
return None

def qname(self, uri):
return self.namespace_manager.qname(uri)

Expand Down Expand Up @@ -1270,15 +1144,6 @@ def parse(
source.close()
return self

def load(self, source, publicID=None, format="xml"):
warn(
DeprecationWarning(
"graph.load() is deprecated, it will be removed in rdflib 6.0.0. "
"Please use graph.parse() instead."
)
)
return self.parse(source, publicID, format)

def query(
self,
query_object,
Expand Down
31 changes: 0 additions & 31 deletions rdflib/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,9 @@
>>> for pic in person.objects(FOAF.depiction):
... print(pic.identifier)
... print(pic.value(RDF.type).qname())
... print(pic.label())
... print(pic.comment())
... print(pic.value(FOAF.thumbnail).identifier)
http://example.org/images/person/some1.jpg
foaf:Image
some 1
Just an image
http://example.org/images/person/some1-thumb.jpg

>>> for cv in person.subjects(CV.aboutPerson):
Expand Down Expand Up @@ -142,18 +138,6 @@
rdf:type
foaf:Image

Similarly, adding, setting and removing data is easy::

>>> thumb.add(RDFS.label, Literal("thumb"))
>>> print(thumb.label())
thumb
>>> thumb.set(RDFS.label, Literal("thumbnail"))
>>> print(thumb.label())
thumbnail
>>> thumb.remove(RDFS.label)
>>> list(thumb.objects(RDFS.label))
[]


Schema Example
--------------
Expand Down Expand Up @@ -201,12 +185,6 @@
>>> [it.qname() for it in choice.value(OWL.oneOf).items()]
[u'v:One', u'v:Other']

And the sequence of Stuff::

>>> stuff = Resource(graph, URIRef("http://example.org/def/v#Stuff"))
>>> [it.qname() for it in stuff.seq()]
[u'v:One', u'v:Other']

On add, other resources are auto-unboxed:
>>> paper = Resource(graph, URIRef("http://example.org/def/v#Paper"))
>>> paper.add(RDFS.subClassOf, artifact)
Expand Down Expand Up @@ -400,12 +378,6 @@ def value(self, p=RDF.value, o=None, default=None, any=True):

return self._cast(self._graph.value(self._identifier, p, o, default, any))

def label(self):
return self._graph.label(self._identifier)

def comment(self):
return self._graph.comment(self._identifier)

def items(self):
return self._resources(self._graph.items(self._identifier))

Expand All @@ -419,9 +391,6 @@ def transitive_subjects(self, predicate, remember=None):
self._graph.transitive_subjects(predicate, self._identifier, remember)
)

def seq(self):
return self._resources(self._graph.seq(self._identifier))

def qname(self):
return self._graph.qname(self._identifier)

Expand Down
2 changes: 1 addition & 1 deletion test/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _str(x):
return None

g = Graph()
g.load(f, publicID=base, format="turtle")
g.parse(f, publicID=base, format="turtle")

for m in g.subjects(RDF.type, MF.Manifest):

Expand Down
2 changes: 1 addition & 1 deletion test/test_canonicalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

def get_digest_value(rdf, mimetype):
graph = Graph()
graph.load(StringIO(rdf), format=mimetype)
graph.parse(StringIO(rdf), format=mimetype)
stats = {}
ig = to_isomorphic(graph)
result = ig.graph_digest(stats)
Expand Down
16 changes: 8 additions & 8 deletions test/test_dawg.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ def update_test(t: RDFTest):

# read input graphs
if data:
g.default_context.load(data, format=_fmt(data))
g.default_context.parse(data, format=_fmt(data))

if graphdata:
for x, l in graphdata:
g.load(x, publicID=URIRef(l), format=_fmt(x))
g.parse(x, publicID=URIRef(l), format=_fmt(x))

with bopen(query_path) as f:
req = translateUpdate(parseUpdate(f))
Expand All @@ -243,11 +243,11 @@ def update_test(t: RDFTest):
# read expected results
resg = Dataset()
if resdata:
resg.default_context.load(resdata, format=_fmt(resdata))
resg.default_context.parse(resdata, format=_fmt(resdata))

if resgraphdata:
for x, l in resgraphdata:
resg.load(x, publicID=URIRef(l), format=_fmt(x))
resg.parse(x, publicID=URIRef(l), format=_fmt(x))

eq(
set(x.identifier for x in g.contexts() if x != g.default_context),
Expand Down Expand Up @@ -355,11 +355,11 @@ def skip(reason="(none)"):
try:
g = Dataset()
if data:
g.default_context.load(data, format=_fmt(data))
g.default_context.parse(data, format=_fmt(data))

if graphdata:
for x in graphdata:
g.load(x, format=_fmt(x))
g.parse(x, format=_fmt(x))

if not resfile:
# no result - syntax test
Expand All @@ -386,11 +386,11 @@ def skip(reason="(none)"):

if resfile.endswith("ttl"):
resg = Graph()
resg.load(resfile, format="turtle", publicID=resfile)
resg.parse(resfile, format="turtle", publicID=resfile)
res = RDFResultParser().parse(resg)
elif resfile.endswith("rdf"):
resg = Graph()
resg.load(resfile, publicID=resfile)
resg.parse(resfile, publicID=resfile)
res = RDFResultParser().parse(resg)
else:
with bopen(resfile_path) as f:
Expand Down
Loading