Package: entityshape
EntityshapeA python library to compare a wikidata item with an entityschemaBased onhttps://github.com/Teester/entityshapeby Mark Tully
andhttps://github.com/dpriskorn/PyEntityshapeby Dennis PriskornFeaturescompare a given wikidata item with an entityschema and dig into missing properties, too many statement, etc.determine whether an item is valid according to a certain schema or notLimitationsThe shape and compareshape classes currently only support:cardinality (too many or not enough values)whether the property is allowed or notwhether the value of a statement on a given property is correct/incorrectIt is still a bit unclear if and how the qualifier validation works.Only Wikidata is supported currently when fetching labels for the result.
If you need support for other Wikibase installations,comment here.InstallationGet it from pypi$ pip install pyentityshapeUsageJupyter NotebooksExample notebooks with code for validation of multiple items:hiking pathscampsitessheltersCLIExample:e = EntityShape(eid="E1", lang="en", qid="Q1")
result = e.validate_and_get_result()
# Get human readable result
print(result)
"Valid: False\nProperties_without_enough_correct_statements: instance of (P31)"
# Access the data
print(result.properties_without_enough_correct_statements)
"{'P31'}"ValidationThe is_valid method on the Result object mimics all red warnings displayed byhttps://www.wikidata.org/wiki/User:Teester/EntityShape.jsIt currently checks these five conditions that all have to be false for the item to be valid:properties with too many statements foundincorrect statements foundsome required properties are missingproperties without enough correct statements foundstatements with properties that are not allowed foundKnown working schemasThis library currently only supports a subset of all features in the ShEx specification.The following Entity Schemas are known to work:hiking pathshelterBackgroundThis library is the glue between libraries likeWikibase
Integratorand entityschemas.It makes it easy to batch check a whole subset of Wikidata
items against a schema. Nice!TODOThe CompareShape and Shape classes should be rewritten using OOP
and enums to avoid passing strings around because that is not
nice to debug or maintain.What do we want to know from the CompareShape class?On the property level:whether the property is mandatory and present/missingOn the statement levelwhether the cardinality of values is allowed (min/max)whether the value(s) are correct/incorrectCases:mandatory property is missingoptional property is missing (this is not invalidating)a property has an incorrect valuea property has a correct valuea property has too many valuesa property has not enough values?ShEx TipWhen working on your Entity Schemas the constraints here are nice to know/rememberhttps://shex.io/shex-primer/#tripleConstraintsThanksBig thanks toMystandChristian Claussfor
advice and help with Ruff to make this better.LicenseGPLv3+What I learnedForking other peoples undocumented spaghetti code is not much fun.I want to find a more reliable validator that support somevalue and novaluePydantic is wonderful yet again it makes working with OOP easy peasy :)Ruff is crazy fast and very nice!