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

Error with prov.entity creation using Identifier as prov.identifier.Identifier as subject #160

Open
dbkeator opened this issue Oct 7, 2024 · 0 comments

Comments

@dbkeator
Copy link

dbkeator commented Oct 7, 2024

Hi,

The following simple example seems to fail with prov version 2.0.1, 2.0.0, and 1.5.3 and I can't figure out why it isn't ok as the requirement is a valid identifier for doc.entity creation and I'm explicitly setting the string-based URI as a prov Identifier. Note, I do not want to use a QualifiedName here but instead use the URI as the identifier. Thx

from prov.model import ProvDocument, Namespace, Identifier, QualifiedName

# Create a new provenance document
doc = ProvDocument()

# Simulate row2 data
row2 = [
    'http://www.cognitiveatlas.org/ontology/cogat.owl#CAO_00962',
    'Autism diagnostic observation schedule'
]

# Define the rdfs namespace
rdfs_ns = Namespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#")

# Create an Identifier for the entity
entity_id = Identifier(row2[0])  # Explicitly create an Identifier from the URI

# Add the entity using the Identifier as the subject and the label as an attribute
entity = doc.entity(
    entity_id,  # Use the Identifier created from the URI
    {QualifiedName(rdfs_ns, "label"): row2[1]}  # Attribute with label
)

# Print the PROV-N output
print(doc.get_provn())

The error is:

Traceback (most recent call last):
File "", line 1, in
File "/Users/dkeator/opt/anaconda3/lib/python3.9/site-packages/prov/model.py", line 1631, in entity
return self.new_record(PROV_ENTITY, identifier, None, other_attributes)
File "/Users/dkeator/opt/anaconda3/lib/python3.9/site-packages/prov/model.py", line 1604, in new_record
new_record = PROV_REC_CLS[record_type](
File "/Users/dkeator/opt/anaconda3/lib/python3.9/site-packages/prov/model.py", line 560, in init
raise ProvElementIdentifierRequired()
prov.model.ProvElementIdentifierRequired: An identifier is missing. All PROV elements require a valid identifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant