From eab5cd9d823ff08c9f2c6a76208061bf4c440711 Mon Sep 17 00:00:00 2001 From: Manuel Namici Date: Thu, 26 Sep 2024 13:29:09 +0200 Subject: [PATCH 1/6] core: owl: avoid adding duplicated annotation assertions These can cause the application to segfault upon removal due to the fact that underlying object are the same and refcount have them deallocated upon removal of the first duplicate. --- eddy/core/owl.py | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/eddy/core/owl.py b/eddy/core/owl.py index affd20d1..464a5a2d 100644 --- a/eddy/core/owl.py +++ b/eddy/core/owl.py @@ -33,6 +33,7 @@ ########################################################################## +from collections import defaultdict from enum import unique import re @@ -48,7 +49,10 @@ from eddy.core.datatypes.common import Enum_ from eddy.core.datatypes.owl import Namespace -from eddy.core.functions.signals import connect +from eddy.core.functions.signals import ( + connect, + disconnect, +) K_FUNCTIONAL = 'functional' K_ASYMMETRIC = 'asymmetric' @@ -59,11 +63,13 @@ K_TRANSITIVE = 'transitive' K_DEPRECATED = 'deprecated' + class Literal(QtCore.QObject): """ Represents Literals """ sgnLiteralModified = QtCore.pyqtSignal() + def __init__(self, lexicalForm, datatype=None, language=None, parent=None): """ :type lexicalForm:str @@ -513,7 +519,7 @@ def __init__(self, namespace,suffix=None, functional=False, invFuctional=False, self._isTransitive = transitive self._manager = None self.components = parse(IRI.concat(self._namespace, self._suffix)) - self._annotationAssertionsMap = {} + self._annotationAssertionsMap = defaultdict(list) self._annotationAssertions = [] @staticmethod @@ -868,33 +874,24 @@ def addAnnotationAssertion(self, annotation): Add an annotation assertion regarding self :type: annotation: AnnotationAssertion """ - if annotation.assertionProperty in self._annotationAssertionsMap: - if not annotation in self._annotationAssertionsMap[annotation.assertionProperty]: - self._annotationAssertionsMap[annotation.assertionProperty].append(annotation) - else: - currList = list() - currList.append(annotation) - self._annotationAssertionsMap[annotation.assertionProperty] = currList - self._annotationAssertions.append(annotation) - self.sgnAnnotationAdded.emit(annotation) - connect(annotation.sgnAnnotationModified, self.onAnnotationAssertionModified) + if annotation not in self._annotationAssertions: + self._annotationAssertions.append(annotation) + self._annotationAssertionsMap[annotation.assertionProperty].append(annotation) + self.sgnAnnotationAdded.emit(annotation) + connect(annotation.sgnAnnotationModified, self.onAnnotationAssertionModified) def removeAnnotationAssertion(self, annotation): """ Remove an annotation assertion regarding self :type: annotation: AnnotationAssertion """ - if annotation.assertionProperty in self._annotationAssertionsMap: - currList = self._annotationAssertionsMap[annotation.assertionProperty] - if annotation in currList: - currList.remove(annotation) - if len(currList) < 1: - self._annotationAssertionsMap.pop(annotation.assertionProperty, None) - if annotation in self._annotationAssertions: - self.annotationAssertions.remove(annotation) - self.sgnAnnotationRemoved.emit(annotation) - else: - raise KeyError('Cannot find the annotation assertion') + if annotation in self._annotationAssertions: + self.annotationAssertions.remove(annotation) + self._annotationAssertionsMap[annotation.assertionProperty].remove(annotation) + if not self._annotationAssertionsMap[annotation.assertionProperty]: + del self._annotationAssertionsMap[annotation.assertionProperty] + self.sgnAnnotationRemoved.emit(annotation) + disconnect(annotation.sgnAnnotationModified, self.onAnnotationAssertionModified) def isAbsolute(self): """ From 4aa6873de04afe55c837aeb1007f5fee9f4499c9 Mon Sep 17 00:00:00 2001 From: Manuel Namici Date: Thu, 26 Sep 2024 13:40:05 +0200 Subject: [PATCH 2/6] ui: ontology: rework to not display duplicated assertions Now these are not part of the project but the callback still adds them. --- eddy/ui/ontology.py | 50 +++++++-------------------------------------- 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/eddy/ui/ontology.py b/eddy/ui/ontology.py index 6e588b17..f44561bf 100644 --- a/eddy/ui/ontology.py +++ b/eddy/ui/ontology.py @@ -1047,28 +1047,10 @@ def addOntologyAnnotation(self, _): :type _: bool """ LOGGER.debug("addOntologyAnnotation called") - assertionBuilder = self.session.doOpenAnnotationAssertionBuilder(self.project.ontologyIRI) #AnnotationAssertionBuilderDialog(self.project.ontologyIRI,self.session) - connect(assertionBuilder.sgnAnnotationAssertionAccepted, self.onOntologyAnnotationAssertionAccepted) + assertionBuilder = self.session.doOpenAnnotationAssertionBuilder(self.project.ontologyIRI) + connect(assertionBuilder.sgnAnnotationAssertionAccepted, self.redraw) assertionBuilder.exec_() - #@QtCore.pyqtSlot(AnnotationAssertion) - def onOntologyAnnotationAssertionAccepted(self,assertion): - """ - :type assertion:AnnotationAssertion - """ - table = self.widget('annotations_table_widget') - rowcount = table.rowCount() - table.setRowCount(rowcount + 1) - propertyItem = QtWidgets.QTableWidgetItem(str(assertion.assertionProperty)) - propertyItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - propertyItem.setData(QtCore.Qt.UserRole,assertion) - table.setItem(rowcount, 0, propertyItem) - valueItem = QtWidgets.QTableWidgetItem(str(assertion.getObjectResourceString(True))) - valueItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - table.setItem(rowcount, 1, QtWidgets.QTableWidgetItem(valueItem)) - table.scrollToItem(table.item(rowcount, 0)) - table.resizeColumnToContents(0) - @QtCore.pyqtSlot(bool) def removeOntologyAnnotation(self, _): """ @@ -1111,31 +1093,13 @@ def editOntologyAnnotation(self, _): for row in range(selectedRange.bottomRow(), selectedRange.topRow() + 1): editItem = table.item(row, 0) assertion = editItem.data(QtCore.Qt.UserRole) - #editItem.setData(None) - assertionBuilder = self.session.doOpenAnnotationAssertionBuilder(self.project.ontologyIRI,assertion) - connect(assertionBuilder.sgnAnnotationAssertionCorrectlyModified,self.onOntologyAnnotationAssertionModified) + assertionBuilder = self.session.doOpenAnnotationAssertionBuilder( + self.project.ontologyIRI, + assertion, + ) + connect(assertionBuilder.sgnAnnotationAssertionCorrectlyModified,self.redraw) assertionBuilder.exec_() - @QtCore.pyqtSlot(AnnotationAssertion) - def onOntologyAnnotationAssertionModified(self,assertion): - """ - :type assertion:AnnotationAssertion - """ - table = self.widget('annotations_table_widget') - rowcount = table.rowCount() - for row in range(0,rowcount): - propItem = table.item(row, 0) - itemAssertion = propItem.data(QtCore.Qt.UserRole) - if itemAssertion is assertion: - newPropertyItem = QtWidgets.QTableWidgetItem(str(assertion.assertionProperty)) - newPropertyItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - newPropertyItem.setData(QtCore.Qt.UserRole, assertion) - table.setItem(row, 0, newPropertyItem) - valueItem = QtWidgets.QTableWidgetItem(str(assertion.getObjectResourceString(True))) - valueItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - table.setItem(row, 1, QtWidgets.QTableWidgetItem(valueItem)) - break - ############################################# # PREFIXES TAB ################################# From 496b7c5d72d710a600589b852660c83a5db73f3d Mon Sep 17 00:00:00 2001 From: Manuel Namici Date: Thu, 26 Sep 2024 13:41:11 +0200 Subject: [PATCH 3/6] ui: iri: rework to not display duplicated assertions Now these are not part of the project but the callback still adds them. --- eddy/ui/iri.py | 43 ++----------------------------------------- 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/eddy/ui/iri.py b/eddy/ui/iri.py index 8059c64d..979fbd7f 100644 --- a/eddy/ui/iri.py +++ b/eddy/ui/iri.py @@ -910,27 +910,9 @@ def addAnnotation(self, _): :type _: bool """ assertionBuilder = self.session.doOpenAnnotationAssertionBuilder(self.iri) - connect(assertionBuilder.sgnAnnotationAssertionAccepted, self.onAnnotationAssertionAccepted) + connect(assertionBuilder.sgnAnnotationAssertionAccepted, self.redraw) assertionBuilder.exec_() - @QtCore.pyqtSlot(AnnotationAssertion) - def onAnnotationAssertionAccepted(self, assertion): - """ - :type assertion:AnnotationAssertion - """ - table = self.widget('annotation_assertions_table_widget') - rowcount = table.rowCount() - table.setRowCount(rowcount + 1) - propertyItem = QtWidgets.QTableWidgetItem(str(assertion.assertionProperty)) - propertyItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - propertyItem.setData(QtCore.Qt.UserRole, assertion) - table.setItem(rowcount, 0, propertyItem) - valueItem = QtWidgets.QTableWidgetItem(str(assertion.getObjectResourceString(True))) - valueItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - table.setItem(rowcount, 1, QtWidgets.QTableWidgetItem(valueItem)) - table.scrollToItem(table.item(rowcount, 0)) - table.resizeColumnToContents(0) - @QtCore.pyqtSlot(bool) def removeAnnotation(self, _): """ @@ -947,7 +929,6 @@ def removeAnnotation(self, _): assertion = removedItem.data(QtCore.Qt.UserRole) command = CommandIRIRemoveAnnotationAssertion(self.project, self.iri, assertion) commands.append(command) - # self.iri.removeAnnotationAssertion(assertion) self.session.undostack.beginMacro('Remove annotations >>') for command in commands: @@ -972,29 +953,9 @@ def editAnnotation(self, _): assertionBuilder = self.session.doOpenAnnotationAssertionBuilder(self.iri, assertion) connect(assertionBuilder.sgnAnnotationAssertionCorrectlyModified, - self.onAnnotationAssertionModified) + self.redraw) assertionBuilder.exec_() - @QtCore.pyqtSlot(AnnotationAssertion) - def onAnnotationAssertionModified(self, assertion): - """ - :type assertion:AnnotationAssertion - """ - table = self.widget('annotation_assertions_table_widget') - rowcount = table.rowCount() - for row in range(0, rowcount): - propItem = table.item(row, 0) - itemAssertion = propItem.data(QtCore.Qt.UserRole) - if itemAssertion is assertion: - newPropertyItem = QtWidgets.QTableWidgetItem(str(assertion.assertionProperty)) - newPropertyItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - newPropertyItem.setData(QtCore.Qt.UserRole, assertion) - table.setItem(row, 0, newPropertyItem) - valueItem = QtWidgets.QTableWidgetItem(str(assertion.getObjectResourceString(True))) - valueItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - table.setItem(row, 1, QtWidgets.QTableWidgetItem(valueItem)) - break - @QtCore.pyqtSlot(int) def onPrefixChanged(self, _): self.onInputChanged('') From 0000ff7183a61460a0e4790c9a0dc50d7a4ccb47 Mon Sep 17 00:00:00 2001 From: Manuel Namici Date: Thu, 26 Sep 2024 16:44:59 +0200 Subject: [PATCH 4/6] ui: iri: keep ui in sync with project annotations Now that duplicate annotation assertions are now part of the project instance, the ui cannot implicitly add the entry to the table as these duplicate annotations are not actually part of the project. Better to reload the list of annotations whenever something gets changed. --- eddy/ui/iri.py | 44 ++------------------------------------------ 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/eddy/ui/iri.py b/eddy/ui/iri.py index 979fbd7f..b7c909ea 100644 --- a/eddy/ui/iri.py +++ b/eddy/ui/iri.py @@ -65,8 +65,6 @@ from eddy.core.items.nodes.literal import LiteralNode from eddy.core.items.nodes.value_domain import ValueDomainNode from eddy.core.owl import ( - Annotation, - AnnotationAssertion, Facet, IllegalLiteralError, IllegalNamespaceError, @@ -1596,27 +1594,9 @@ def addAnnotation(self, _): :type _: bool """ annotationBuilder = self.session.doOpenAnnotationBuilder(self.edge) - connect(annotationBuilder.sgnAnnotationAccepted, self.onAnnotationAccepted) + connect(annotationBuilder.sgnAnnotationAccepted, self.redraw) annotationBuilder.exec_() - @QtCore.pyqtSlot(AnnotationAssertion) - def onAnnotationAccepted(self, annotation): - """ - :type annotation:Annotation - """ - table = self.widget('annotations_table_widget') - rowcount = table.rowCount() - table.setRowCount(rowcount + 1) - propertyItem = QtWidgets.QTableWidgetItem(str(annotation.assertionProperty)) - propertyItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - propertyItem.setData(QtCore.Qt.UserRole, annotation) - table.setItem(rowcount, 0, propertyItem) - valueItem = QtWidgets.QTableWidgetItem(str(annotation.getObjectResourceString(True))) - valueItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - table.setItem(rowcount, 1, QtWidgets.QTableWidgetItem(valueItem)) - table.scrollToItem(table.item(rowcount, 0)) - table.resizeColumnToContents(0) - @QtCore.pyqtSlot(bool) def removeAnnotation(self, _): """ @@ -1655,29 +1635,9 @@ def editAnnotation(self, _): editItem = table.item(row, 0) annotation = editItem.data(QtCore.Qt.UserRole) annotationBuilder = self.session.doOpenAnnotationBuilder(self.edge, annotation) - connect(annotationBuilder.sgnAnnotationCorrectlyModified, self.onAnnotationModified) + connect(annotationBuilder.sgnAnnotationCorrectlyModified, self.redraw) annotationBuilder.exec_() - @QtCore.pyqtSlot(Annotation) - def onAnnotationModified(self, assertion): - """ - :type assertion:Annotation - """ - table = self.widget('annotations_table_widget') - rowcount = table.rowCount() - for row in range(0, rowcount): - propItem = table.item(row, 0) - itemAssertion = propItem.data(QtCore.Qt.UserRole) - if itemAssertion is assertion: - newPropertyItem = QtWidgets.QTableWidgetItem(str(assertion.assertionProperty)) - newPropertyItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - newPropertyItem.setData(QtCore.Qt.UserRole, assertion) - table.setItem(row, 0, newPropertyItem) - valueItem = QtWidgets.QTableWidgetItem(str(assertion.getObjectResourceString(True))) - valueItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) - table.setItem(row, 1, QtWidgets.QTableWidgetItem(valueItem)) - break - @QtCore.pyqtSlot(int) def onPrefixChanged(self, _): self.onInputChanged('') From 4ccc066cf15edd5209296ee047cd10508dcaf115 Mon Sep 17 00:00:00 2001 From: Manuel Namici Date: Thu, 26 Sep 2024 17:01:46 +0200 Subject: [PATCH 5/6] ui: annotation: better deal with dummy datatype and lang tags Prior to this there could have been cases where, in particular, the lang tag was simply a whitespace string. This does not make much sense so try to strip whitespace saving the assertion. --- eddy/ui/annotation.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/eddy/ui/annotation.py b/eddy/ui/annotation.py index 5c1d7c21..76443610 100644 --- a/eddy/ui/annotation.py +++ b/eddy/ui/annotation.py @@ -406,24 +406,21 @@ def onInputChanged(self, _): @QtCore.pyqtSlot() def accept(self): - - subjectStr = self.widget('subject_switch').currentText() + subjectStr = self.widget('subject_switch').currentText().strip() subjectIRI = self.project.getIRI(subjectStr) - propertyStr = self.widget('property_switch').currentText() + propertyStr = self.widget('property_switch').currentText().strip() propertyIRI = self.project.getIRI(propertyStr) activeTab = self.widget('main_widget').currentWidget() if activeTab is self.widget('literal_widget'): value = self.widget('value_textedit').toPlainText() if not value: value = ' ' - typeStr = self.widget('type_switch').currentText() - typeIRI = None - if typeStr: - typeIRI = self.project.getIRI(typeStr) - language = None + typeStr = self.widget('type_switch').currentText().strip() + typeIRI = self.project.getIRI(typeStr) if typeStr else None if self.widget('lang_switch').isEnabled(): - language = self.widget('lang_switch').currentText() - if language not in self.project.getLanguages(): + langStr = self.widget('lang_switch').currentText().strip() + language = langStr if langStr else None + if language and language not in self.project.getLanguages(): self.project.addLanguageTag(language) else: value = self.widget('full_iri_field').value() @@ -431,7 +428,7 @@ def accept(self): parse(value, rule='IRI') value = self.project.getIRI(value) typeIRI = self.project.getIRI('http://www.w3.org/2001/XMLSchema#anyURI') - language = '' + language = None except ValueError: dialog = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Warning, @@ -640,19 +637,17 @@ def onTypeSwitched(self, index): @QtCore.pyqtSlot() def accept(self): - propertyStr = self.widget('property_switch').currentText() + propertyStr = self.widget('property_switch').currentText().strip() propertyIRI = self.project.getIRI(propertyStr) value = self.widget('value_textedit').toPlainText() if not value: value = ' ' - typeStr = self.widget('type_switch').currentText() - typeIRI = None - if typeStr: - typeIRI = self.project.getIRI(typeStr) - language = None + typeStr = self.widget('type_switch').currentText().strip() + typeIRI = self.project.getIRI(typeStr) if typeStr else None if self.widget('lang_switch').isEnabled(): - language = self.widget('lang_switch').currentText() - if language not in self.project.getLanguages(): + langStr = self.widget('lang_switch').currentText().strip() + language = langStr if langStr else None + if language and language not in self.project.getLanguages(): self.project.addLanguageTag(language) if not self.annotation: annotation = Annotation(propertyIRI, value, typeIRI, language) From ab0e524ffd92b2f8ba0cce75e45dbe9d13b9ffa3 Mon Sep 17 00:00:00 2001 From: Manuel Namici Date: Thu, 26 Sep 2024 17:07:22 +0200 Subject: [PATCH 6/6] core: owl, items: fix duplicate assertion handling also for axiom annotations --- eddy/core/items/edges/common/base.py | 41 +++++++-------- eddy/core/owl.py | 78 +++++++++++++--------------- 2 files changed, 53 insertions(+), 66 deletions(-) diff --git a/eddy/core/items/edges/common/base.py b/eddy/core/items/edges/common/base.py index a5445ad9..7f266975 100644 --- a/eddy/core/items/edges/common/base.py +++ b/eddy/core/items/edges/common/base.py @@ -33,11 +33,16 @@ ########################################################################## -from abc import ABCMeta, abstractmethod -from itertools import permutations +from abc import ( + ABCMeta, + abstractmethod, +) +from collections import defaultdict -from PyQt5 import QtCore -from PyQt5 import QtGui +from PyQt5 import ( + QtCore, + QtGui, +) from eddy.core.commands.edges import CommandEdgeAnchorMove from eddy.core.commands.edges import CommandEdgeBreakpointAdd @@ -541,7 +546,7 @@ class AxiomEdge(AbstractEdge): def __init__(self,**kwargs): super().__init__(**kwargs) - self._annotationsMap = {} + self._annotationsMap = defaultdict(list) self._annotations = [] @property @@ -567,27 +572,17 @@ def addAnnotation(self, annotation): Add an annotation regarding self :type: annotation: Annotation """ - if annotation.assertionProperty in self._annotationsMap: - if not annotation in self._annotationsMap[annotation.assertionProperty]: - self._annotationsMap[annotation.assertionProperty].append(annotation) - else: - currList = list() - currList.append(annotation) - self._annotationsMap[annotation.assertionProperty] = currList - self.annotations.append(annotation) + if annotation not in self.annotations: + self.annotations.append(annotation) + self._annotationsMap[annotation.assertionProperty].append(annotation) def removeAnnotation(self, annotation): """ Remove an annotation regarding self :type: annotation: Annotation """ - if annotation.assertionProperty in self._annotationsMap: - currList = self._annotationsMap[annotation.assertionProperty] - if annotation in currList: - currList.remove(annotation) - if len(currList) < 1: - self._annotationsMap.pop(annotation.assertionProperty, None) - if annotation in self.annotations: - self.annotations.remove(annotation) - else: - raise KeyError('Cannot find the annotation') + if annotation in self.annotations: + self.annotations.remove(annotation) + self._annotationsMap[annotation.assertionProperty].remove(annotation) + if not self._annotationsMap[annotation.assertionProperty]: + del self._annotationsMap[annotation.assertionProperty] diff --git a/eddy/core/owl.py b/eddy/core/owl.py index 464a5a2d..9c9b3152 100644 --- a/eddy/core/owl.py +++ b/eddy/core/owl.py @@ -147,6 +147,7 @@ def __str__(self): def __repr__(self): return str(self) + class Facet(QtCore.QObject): """ Represents Annotation Assertions @@ -194,6 +195,7 @@ def __str__(self): def __repr__(self): return str(self) + class Annotation(QtCore.QObject): """ Represents Annotations @@ -212,6 +214,10 @@ def __init__(self, property, value, type=None, language=None, parent=None): self._property = property if not (isinstance(value, IRI) or isinstance(value, str)): raise ValueError('The value of an annotation must be either an IRI or a string') + if isinstance(type, str) and type.isspace(): + type = None + if isinstance(language, str) and language.isspace(): + language = None self._value = value self._datatype = type self._language = language @@ -297,20 +303,6 @@ def getObjectResourceString(self, prefixedForm): else: result += '^^<{}>'.format(self.datatype) return result - ''' - result = '' - if self._language: - result += '"{}@{}"'.format(self._value,self._language) - else: - result = '"{}"'.format(self._value) - if self._datatype: - prefixedType = self._datatype.manager.getShortestPrefixedForm(self._datatype) - if prefixedForm and prefixedType: - result += '^^{}'.format(str(prefixedType)) - else: - result += '^^<{}>'.format(self._datatype) - return result - ''' def __hash__(self): result = self._property.__hash__() @@ -326,9 +318,13 @@ def __hash__(self): return result def __eq__(self, other): - if not isinstance(other, AnnotationAssertion): - return False - return self.assertionProperty == other.assertionProperty and self.value == other.value and self.datatype == other.datatype and self.language == other.value + return ( + isinstance(other, Annotation) + and self.assertionProperty == other.assertionProperty + and self.value == other.value + and self.datatype == other.datatype + and self.language == other.language + ) def __str__(self): return 'Annotation(<{}> {})'.format(self.assertionProperty,self.getObjectResourceString(True)) @@ -336,6 +332,7 @@ def __str__(self): def __repr__(self): return str(self) + class AnnotationAssertion(QtCore.QObject): """ Represents Annotation Assertions @@ -355,6 +352,10 @@ def __init__(self, subject, property, value, type=None, language=None, parent=No self._property = property if not (isinstance(value, IRI) or isinstance(value, str)): raise ValueError('The value of an annotation assertion must be either an IRI or a string') + if isinstance(type, str) and type.isspace(): + type = None + if isinstance(language, str) and language.isspace(): + language = None self._value = value self._datatype = type self._language = language @@ -444,20 +445,6 @@ def getObjectResourceString(self, prefixedForm): else: result += '^^<{}>'.format(self.datatype) return result - ''' - result = '' - if self._language: - result += '"{}@{}"'.format(self._value,self._language) - else: - result = '"{}"'.format(self._value) - if self._datatype: - prefixedType = self._datatype.manager.getShortestPrefixedForm(self._datatype) - if prefixedForm and prefixedType: - result += '^^{}'.format(str(prefixedType)) - else: - result += '^^<{}>'.format(self._datatype) - return result - ''' def __hash__(self): result = self._property.__hash__() @@ -473,20 +460,25 @@ def __hash__(self): return result def __eq__(self, other): - if not isinstance(other, AnnotationAssertion): - return False - return (self.assertionProperty == other.assertionProperty and - self.subject == other.subject and - self.value == other.value and - self.datatype == other.datatype and - self.language == other.language) + return ( + isinstance(other, AnnotationAssertion) + and self.assertionProperty == other.assertionProperty + and self.subject == other.subject + and self.value == other.value + and self.datatype == other.datatype + and self.language == other.language + ) def __str__(self): - return 'AnnotationAssertion(<{}> <{}> {})'.format(self.assertionProperty,self.subject,self.getObjectResourceString(True)) + return 'AnnotationAssertion(<{}> <{}> {})'.format( + self.assertionProperty,self.subject, + self.getObjectResourceString(True), + ) def __repr__(self): return str(self) + class IRI(QtCore.QObject): """ Represents International Resource Identifiers (https://www.ietf.org/rfc/rfc3987.txt) @@ -765,9 +757,9 @@ def scheme(self): # INTERFACE ################################# def setMetaProperties(self, metaDict): - ''' + """ :type: metaDict: dict - ''' + """ for k,v in metaDict.items(): if k==K_FUNCTIONAL: self.functional = v @@ -853,10 +845,10 @@ def getAllLabelAnnotationAssertions(self): return None def getLabelAnnotationAssertion(self, lang=None): - ''' + """ :type lang:str :rtype AnnotationAssertion - ''' + """ return self.getAnnotationAssertion(AnnotationAssertionProperty.Label.value, lang=lang) def getAnnotationAssertion(self, annotationProperty, lang=None):