@@ -512,7 +512,7 @@ def setup_editor(self, ontology) -> None:
512512 ontology (Ontology): The ontology to attach to the project
513513 """
514514 if self .labeling_frontend () is not None :
515- raise ResourceConflict ("Editor is already set up" )
515+ raise ResourceConflict ("Editor is already set up. Use project.connect_ontology to change an ontology. " )
516516
517517 labeling_frontend = next (
518518 self .client .get_labeling_frontends (
@@ -542,6 +542,21 @@ def setup_editor(self, ontology) -> None:
542542 timestamp = datetime .now (timezone .utc ).strftime ("%Y-%m-%dT%H:%M:%SZ" )
543543 self .update (setup_complete = timestamp )
544544
545+ def connect_ontology (self , ontology ) -> None :
546+ """
547+ Connect an ontology to the project.
548+
549+ Args:
550+ ontology (Ontology): The ontology to attach to the project
551+ """
552+ query_str = """mutation ConnectOntologyPyApi($projectId: ID!, $ontologyId: ID!){
553+ project(where: {id: $projectId}) {connectOntology(ontologyId: $ontologyId) {id}}}"""
554+ self .client .execute (query_str , {
555+ 'ontologyId' : ontology .uid ,
556+ 'projectId' : self .uid
557+ })
558+
559+
545560 def setup (self , labeling_frontend , labeling_frontend_options ) -> None :
546561 """ Finalizes the Project setup.
547562
@@ -554,7 +569,7 @@ def setup(self, labeling_frontend, labeling_frontend_options) -> None:
554569 """
555570
556571 if self .labeling_frontend () is not None :
557- raise ResourceConflict ("Editor is already set up" )
572+ raise ResourceConflict ("Editor is already set up. Use project.connect_ontology to change an ontology. " )
558573
559574 if not isinstance (labeling_frontend_options , str ):
560575 labeling_frontend_options = json .dumps (labeling_frontend_options )
0 commit comments