-
Notifications
You must be signed in to change notification settings - Fork 14
First version of added namespace search in get_by_label #838
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
768118c
bcafad0
79acb31
dd99912
3390620
d5a6ea5
00e8d9a
3aadfee
6782a73
652951a
d5ab563
04b46f9
46926c6
64d0f8d
0b96a02
172af04
5f4b4ec
f106279
861a348
5d47dde
8a13a0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -377,8 +377,9 @@ def get_by_label( | |
| "Namespace given in argument is ignored. " | ||
| ) | ||
| namespace = splitlabel[0] | ||
|
|
||
| #print('namespace', namespace) | ||
| if namespace: | ||
| #print('in get_by_label namespavce') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be removed |
||
| entityset = self.get_by_label_all( | ||
francescalb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| label, | ||
| label_annotations=label_annotations, | ||
|
|
@@ -388,7 +389,7 @@ def get_by_label( | |
| return entityset.pop() | ||
| raise NoSuchLabelError( | ||
| f"No label annotations matches for '{label}' " | ||
| f"with prefix '{prefix}'." | ||
| f"with namespace '{namespace}'." | ||
| ) | ||
|
|
||
| if prefix: | ||
|
|
@@ -518,13 +519,13 @@ def get_by_label_all( | |
| ent for ent in self.get_entities() if ent.name in matches | ||
| ) | ||
| if namespace: | ||
| print("in namespace", namespace) | ||
| print("entities", entities) | ||
| for ent in entities: | ||
| print("ent.namespace", ent.namespace) | ||
| print("ent.namespace.name", ent.namespace.name) | ||
| print("namespace", namespace) | ||
| print(namespace in [ent.namespace.name, ent.namespace.base_iri]) | ||
| #print("in namespace", namespace) | ||
| #print("entities", entities) | ||
| #for ent in entities: | ||
| # print("ent.namespace", ent.namespace) | ||
| # print("ent.namespace.name", ent.namespace.name) | ||
| # print("namespace", namespace) | ||
| # print(namespace in [ent.namespace.name, ent.namespace.base_iri]) | ||
|
Comment on lines
+522
to
+528
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be removed |
||
| return set( | ||
| ent | ||
| for ent in entities | ||
|
|
@@ -2060,7 +2061,7 @@ def get_wu_palmer_measure(self, cls1, cls2): | |
| generations2 = self.number_of_generations(cls2, cca) | ||
| return 2 * ccadepth / (generations1 + generations2 + 2 * ccadepth) | ||
|
|
||
| def new_entity( | ||
| def new_entity( # pylint: disable=too-many-arguments,too-many-branches,too-many-positional-arguments | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These pylint disable's will probably make the line too long. Probably better to move the comment to after the docstring (line 2119) |
||
| self, | ||
| name: str, | ||
| parent: Union[ | ||
|
|
@@ -2080,6 +2081,7 @@ def new_entity( | |
| ] | ||
| ] = "class", | ||
| preflabel: Optional[str] = None, | ||
| iri: Optional[str] = None, | ||
| ) -> Union[ | ||
| ThingClass, | ||
| ObjectPropertyClass, | ||
|
|
@@ -2103,6 +2105,8 @@ def new_entity( | |
| be added as prefLabel if skos:prefLabel is in the ontology | ||
| and listed in `self.label_annotations`. Set `preflabel` to | ||
| False, to avoid assigning a prefLabel. | ||
| iri: IRI of the entity. If None, a new IRI will be generated | ||
| based on the ontology base IRI and the entity name. | ||
|
|
||
| Returns: | ||
| the new entity. | ||
|
|
@@ -2148,7 +2152,8 @@ def new_entity( | |
|
|
||
| with self: | ||
| entity = types.new_class(name, parents) | ||
|
|
||
| if iri: | ||
| entity.iri = iri | ||
| preflabel_iri = "http://www.w3.org/2004/02/skos/core#prefLabel" | ||
| if preflabel: | ||
| if not self.world[preflabel_iri]: | ||
|
|
@@ -2169,63 +2174,81 @@ def new_entity( | |
|
|
||
| # Method that creates new ThingClass using new_entity | ||
| def new_class( | ||
| self, name: str, parent: Union[ThingClass, Iterable] | ||
| self, | ||
| name: str, | ||
| parent: Union[ThingClass, Iterable], | ||
| iri: Optional[str] = None, | ||
| ) -> ThingClass: | ||
| """Create and return new class. | ||
|
|
||
| Args: | ||
| name: name of the class | ||
| parent: parent(s) of the class | ||
| iri: IRI of the new class. If None, a new IRI will be generated | ||
| based on the ontology base IRI and the entity name. | ||
|
|
||
|
|
||
| Returns: | ||
| the new class. | ||
| """ | ||
| return self.new_entity(name, parent, "class") | ||
| return self.new_entity(name, parent, "class", iri=iri) | ||
|
|
||
| # Method that creates new ObjectPropertyClass using new_entity | ||
| def new_object_property( | ||
| self, name: str, parent: Union[ObjectPropertyClass, Iterable] | ||
| self, | ||
| name: str, | ||
| parent: Union[ObjectPropertyClass, Iterable], | ||
| iri: Optional[str] = None, | ||
| ) -> ObjectPropertyClass: | ||
| """Create and return new object property. | ||
|
|
||
| Args: | ||
| name: name of the object property | ||
| parent: parent(s) of the object property | ||
|
|
||
| iri: IRI of the new object property. If None, a new IRI will be | ||
| based on the ontology base IRI and the entity name. | ||
| Returns: | ||
| the new object property. | ||
| """ | ||
| return self.new_entity(name, parent, "object_property") | ||
| return self.new_entity(name, parent, "object_property", iri=iri) | ||
|
|
||
| # Method that creates new DataPropertyClass using new_entity | ||
| def new_data_property( | ||
| self, name: str, parent: Union[DataPropertyClass, Iterable] | ||
| self, | ||
| name: str, | ||
| parent: Union[DataPropertyClass, Iterable], | ||
| iri: Optional[str] = None, | ||
| ) -> DataPropertyClass: | ||
| """Create and return new data property. | ||
|
|
||
| Args: | ||
| name: name of the data property | ||
| parent: parent(s) of the data property | ||
|
|
||
| iri: IRI of the new data property. If None, a new IRI will be | ||
| based on the ontology base IRI and the entity name | ||
| Returns: | ||
| the new data property. | ||
| """ | ||
| return self.new_entity(name, parent, "data_property") | ||
| return self.new_entity(name, parent, "data_property", iri=iri) | ||
|
|
||
| # Method that creates new AnnotationPropertyClass using new_entity | ||
| def new_annotation_property( | ||
| self, name: str, parent: Union[AnnotationPropertyClass, Iterable] | ||
| self, | ||
| name: str, | ||
| parent: Union[AnnotationPropertyClass, Iterable], | ||
| iri: Optional[str] = None, | ||
| ) -> AnnotationPropertyClass: | ||
| """Create and return new annotation property. | ||
|
|
||
| Args: | ||
| name: name of the annotation property | ||
| parent: parent(s) of the annotation property | ||
|
|
||
| iri: IRI of the new annotation property. If None, a new IRI will | ||
| be based on the ontology base IRI and the entity name. | ||
| Returns: | ||
| the new annotation property. | ||
| """ | ||
| return self.new_entity(name, parent, "annotation_property") | ||
| return self.new_entity(name, parent, "annotation_property", iri=iri) | ||
|
|
||
| def difference(self, other: owlready2.Ontology) -> set: | ||
| """Return a set of triples that are in this, but not in the | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be removed