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

Remove project name #264

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions eddy/core/loaders/owl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def createProject(self):
"""
ontologyIRI, ontologyV = self.getOntologyID()
self.nproject = Project(
name=ontologyIRI,
parent=self.session,
profile=self.session.createProfile('OWL 2'),
ontologyIRI=ontologyIRI,
Expand Down
19 changes: 18 additions & 1 deletion eddy/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
QtCore,
QtWidgets,
)
from rfc3987 import parse

from eddy.core.datatypes.graphol import Item
from eddy.core.diagram import Diagram
Expand Down Expand Up @@ -159,7 +160,7 @@ def __init__(
"""
super().__init__(**kwargs)
self.index = ProjectIRIIndex(self)
self.name = name
self.oldName = name
self.path = expandPath(path) if path else None
self.profile = profile
self.profile.setParent(self)
Expand All @@ -183,6 +184,22 @@ def session(self) -> 'Session':
"""
return cast('Session', self.parent())

@property
def name(self):
try:
parse(str(self.ontologyIRI), rule='IRI')
name = str(self.ontologyIRI)
except ValueError:
name = "http://obda.org/"+self.oldName
simpleName = self.getIRI(name).getSimpleName()
return simpleName if len(simpleName) > 0 else self.oldName
Comment on lines +194 to +195
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sto notando che se si una un IRI dell'ontologia che termina con # o / questo metodo fallisce sempre (viene restituito l'oldName) e non si riesce a far aggiornare il nome in quanto getSimpleName() restituisce la stringa vuota su queste IRI. Sto cercando di capire se è un problema di getSimpleName o se possiamo fare qualcosa per evitarlo.

@name.setter
def name(self, value):
try:
parse(value, rule='IRI')
self.ontologyIRI = self.getIRI(value)
except ValueError:
self.ontologyIRI = self.getIRI("http://obda.org/"+value)
#############################################
# INTERFACE
#################################
Expand Down
21 changes: 11 additions & 10 deletions eddy/ui/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
QtWidgets,
QtXmlPatterns,
)
from rfc3987 import parse

from eddy.core.functions.misc import isEmpty
from eddy.core.functions.signals import connect
Expand All @@ -61,12 +62,6 @@ def __init__(self, parent: QtWidgets.QWidget = None) -> None:
# FORM AREA
#################################

self.nameLabel = QtWidgets.QLabel(self)
self.nameLabel.setText('Project name')
self.nameField = StringField(self)
self.nameField.setMinimumWidth(400)
self.nameField.setMaxLength(64)

self.iriLabel = QtWidgets.QLabel(self)
self.iriLabel.setText('Ontology IRI')
self.iriField = StringField(self)
Expand All @@ -79,15 +74,13 @@ def __init__(self, parent: QtWidgets.QWidget = None) -> None:

connect(self.prefixField.textChanged, self.doValidateForm)
connect(self.iriField.textChanged, self.doValidateForm)
connect(self.nameField.textChanged, self.doValidateForm)

spacer = QtWidgets.QFrame()
spacer.setFrameShape(QtWidgets.QFrame.HLine)
spacer.setFrameShadow(QtWidgets.QFrame.Sunken)

self.formWidget = QtWidgets.QWidget(self)
self.formLayout = QtWidgets.QFormLayout(self.formWidget)
self.formLayout.addRow(self.nameLabel, self.nameField)
self.formLayout.addRow(self.iriLabel, self.iriField)
self.formLayout.addRow(self.prefixLabel, self.prefixField)
self.formLayout.addWidget(spacer)
Expand Down Expand Up @@ -132,13 +125,21 @@ def iri(self) -> str:
"""
Returns the value of the iri field (trimmed).
"""
return self.iriField.value()
try:
parse(self.iriField.value(), rule='IRI')
return self.iriField.value()
except ValueError:
return "http://obda.org/" + self.iriField.value()

def name(self) -> str:
"""
Returns the value of the name field (trimmed).
"""
return self.nameField.value()
try:
parse(self.iriField.value(), rule='IRI')
return self.iriField.value()
except ValueError:
return "http://obda.org/" + self.iriField.value()

def prefix(self) -> str:
"""
Expand Down
27 changes: 23 additions & 4 deletions eddy/ui/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
shortPath,
)
from eddy.core.functions.signals import connect
from eddy.core.jvm import getJavaVM
from eddy.ui.file import FileDialog
from eddy.ui.project import (
NewProjectDialog,
Expand Down Expand Up @@ -347,10 +348,28 @@ def doImportFromOWL(self):
dialog.setNameFilters([File.Owl.value])
if dialog.exec_() == QtWidgets.QFileDialog.Accepted:
filePath = dialog.selectedFiles()[0]
form = ProjectFromOWLDialog(self)
if form.exec_() == ProjectFromOWLDialog.Accepted:
self.sgnCreateSession[str, str, str, str, str].emit(
None, form.name(), None, None, str(filePath))
# get ontology IRI to assign as project name
vm = getJavaVM()
if not vm.isRunning():
vm.initialize()
vm.attachThreadToJVM()
JavaFileClass = vm.getJavaClass('java.io.File')
OWLManager = vm.getJavaClass('org.semanticweb.owlapi.apibinding.OWLManager')
MissingImportHandlingStrategy = vm.getJavaClass(
'org.semanticweb.owlapi.model.MissingImportHandlingStrategy')
fileInstance = JavaFileClass(filePath)
manager = OWLManager().createOWLOntologyManager()
config = manager.getOntologyLoaderConfiguration()
config = config.setMissingImportHandlingStrategy(
MissingImportHandlingStrategy.SILENT)
manager.setOntologyLoaderConfiguration(config)
ontology = manager.loadOntologyFromOntologyDocument(
fileInstance)

ontology_iri = ontology.getOntologyID().getOntologyIRI().get().toString()
self.sgnCreateSession[str, str, str, str, str].emit(
None, ontology_iri, None, None, str(filePath))


@QtCore.pyqtSlot(str)
def doRemoveProject(self, path: str) -> None:
Expand Down