-
Notifications
You must be signed in to change notification settings - Fork 558
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
Bug: Unexpected namespace creation during turtle file serialization #2779
Comments
Running into the same issue |
Please solve this! |
Quick Note: I've been able to patch this bug for now by overriding the class FixedTurtleSerializer(TurtleSerializer):
def getQName(self, uri, gen_prefix=True):
return super().getQName(uri, gen_prefix=False) This fixes the fact that there are multiple places in this serializer that call the method. I'm considering throwing in a PR to adjust the behavior of serialize to not generate namespaces by default since:
A possible method could look like: g = rdflib.Graph(bind_namespaces="none")
serialized_without_prefixes = g.serialize(format="turtle", generate_prefixes=False)
serialized_with_prefixes = g.serialize(format="turtle", generate_prefixes=True) Any thoughts? I could also go with the reverse approach where the default behavior remains the same and an optional param is added to disable the predicate prefix generation. This would be non-breaking, but could be less intuitive for new users. |
Having the two options - to generate and to not generate prefixes - with a documented default sounds great, please do make a PR! |
Hello! I've noticed that serializing a ttl file has an unexpected behavior where adding a triple to a blank graph and then serializing it randomly adds a prefix to the turtle file:
Results in:
When someone would expect:
I've boiled it down to the following line:
rdflib/rdflib/plugins/serializers/turtle.py
Line 270 in fb43b7a
Here we create a new prefix if we're looking at the predicate of a triple during serialization. I can't follow the blame of this change or docs explaining that serialize modifies the graph. Does anyone know why this was put there and if it can be set to
self.getQName(node, gen_prefix=False)
? This seems to have already been done for trig files #2467 .The text was updated successfully, but these errors were encountered: