Editing a Managed Model

Managed models that are generated by a Direct Load Step are owned and managed by the data layer that contains the Direct Load Step. Any changes made to the model outside of the step, such as from the Model editor, are overwritten any time the graphmart or layer is refreshed or reloaded. This topic provides guidance on updating the properties in a managed model by editing the Direct Load Step query.

Before starting the procedure, you might want to start another session of Anzo. In the new session, open in the Model editor the model that you will be updating. That way you can copy model, class, and property URIs from the model while you edit the Direct Load Step query.

  1. In the graphmart for which you want to update a model, click the Data Layers tab. Expand the layer that was generated when you created the graphmart and find the Direct Load Step that inserts the data.
  2. Open the Direct Load Step for editing and click the Query tab. For example, the image below shows the query that was generated to onboard data about books from a CSV file:

  3. Make sure the following prefixes are declared in the PREFIX clause at the top of the query. If any are missing, add them to the query:
    PREFIX owl: <http://www.w3.org/2002/07/owl#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
  4. Next, add the following GRAPH clause statements under the SERVICE clause:
    GRAPH <model_URI> { 
      <property_URI> a owl:DatatypeProperty;
        rdfs:comment "comment" ; 
        rdfs:label "property_label" ; 
        rdfs:domain <class_URI> ; 
        rdfs:range <dataype> .
    [ <property2_URI> a owl:DatatypeProperty;
        rdfs:comment "comment" ; 
        rdfs:label "property2_label" ; 
        rdfs:domain <class_URI> ; 
        rdfs:range <datatype> . ]
    [ ... ]
    }
    • model_URI: The URI of the model that was generated by the Direct Load Step. You can copy the URI from the Model editor from the Details tab for the model. For example:
      <http://cambridgesemantics.com/Layer/698d17.../Model>
    • property_URI: The URI to use for the new property or the URI of the existing property that you want to update. When adding a property, you can look at the URIs for other properties in the model and follow the same scheme. For example:
      <http://cambridgesemantics.com/Layer/6.../Model#GoodReads100kBooks.FirstPrint>
    • comment: A string that describes the property. For example, "Date the book first went to print".
    • property_label: The label to give the property. For example, "First Print Date".
    • class_URI: The URI of the class that the existing property belongs to or the new property should be added to. You can copy the URI from the Model editor from the Details tab for the class. For example:
      <http://cambridgesemantics.com/Layer/698d1794.../Model#GoodReads100kBooks>
    • datatype: The URI for the datatype of the property. For example, xsd:date.

    For example, the following query adds one new property to the model that is generated by the Direct Load Step query shown above:

    PREFIX good_reads_books_files: <http://cambridgesemantics.com/DataSource/0e5ab8601249264a318b4a4bcfa81700/Good_Reads_Books/>
    PREFIX s: <http://cambridgesemantics.com/ontologies/DataToolkit#>
    PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
    PREFIX owl: <http://www.w3.org/2002/07/owl#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    INSERT {
      GRAPH ${targetGraph} {
        ?subject ?predicate ?object .
      }
    }
    WHERE {
      SERVICE <http://cambridgesemantics.com/services/DataToolkit> {
        GRAPH <http://cambridgesemantics.com/Layer/698d179498f945a393f8a91ee9f1f611/Model> {
          <http://cambridgesemantics.com/Layer/698d179498f945a393f8a91ee9f1f611/Model#GoodReads100kBooks.FirstPrint> a owl:DatatypeProperty;
          rdfs:comment "Date the book first went to print" ;
          rdfs:label "First Print Date" ;
          rdfs:domain <http://cambridgesemantics.com/Layer/698d179498f945a393f8a91ee9f1f611/Model#GoodReads100kBooks> ;
          rdfs:range xsd:date .
      }
        []
          s:segment "false"^^xsd:boolean .
        ?generator a s:RdfGenerator, s:OntologyGenerator ;
          s:as (?subject ?predicate ?object) ;
          s:base ${targetGraph} .
     
        good_reads_books_files:GoodReads_100k_books a s:FileSource ;
          s:url "/nfs/data/csv/GoodReads_100k_books.csv" ;
          s:model "GoodReads_100k_books" .
      }
    }
  5. Next, if you added properties and the class for any of the new properties does not have a primary key defined, you must create a key for that class. If all of the classes you referenced in the query have primary keys, you can continue to the next step. If one or more of the classes do not have primary keys, follow the instructions below:
    1. Locate in the query the statement block for each class that needs a key defintion. For example, in the query above, there is only one class, s:model "GoodReads_100k_Books". If you have multiple classes, the query has several blocks, such as this example:
      ...
      emrdbsmall:emr_complaint a s:DbSource ; s:using mysql_db:MySQL_DB ; s:table "emrdbsmall.emr_complaint" ; s:model "emr_complaint" . emrdbsmall:emr_patient a s:DbSource ; s:using mysql_db:MySQL_DB ; s:table "emrdbsmall.emr_patient" ; s:model "emr_patient" . emrdbsmall:emr_complaintdescription a s:DbSource ; s:using mysql_db:MySQL_DB ; s:table "emrdbsmall.emr_complaintdescription" ; s:model "emr_complaintdescription" . ...
    2. At the end of the block for the class you want to add a key to, change the period (.) after s:model to a semicolon (;).
    3. Next, add the following line below s:model:
      s:key ("key_property" [, "key_property2" ] [, ... ]) .

      Where key_property is the label of the property to use as a key for the class. The property that you choose must have unique values. If there is not a property in the class with unique values, you can specify a combination of properties that would create a unique value. Make sure that the value of key_property matches the label for that property in the model. For example, for the query in step 4, the Isbn property can be used as a unique key for the GoodReads_100k_Books class:

      good_reads_books_files:GoodReads_100k_books a s:FileSource ;
        s:url "/nfs/data/csv/GoodReads_100k_books.csv" ;
        s:model "GoodReads_100k_books" ;
        s:key ("Isbn") .

      The final, completed query is shown below:

      PREFIX good_reads_books_files: <http://cambridgesemantics.com/DataSource/0e5ab8601249264a318b4a4bcfa81700/Good_Reads_Books/>
      PREFIX s: <http://cambridgesemantics.com/ontologies/DataToolkit#>
      PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
      PREFIX owl: <http://www.w3.org/2002/07/owl#>
      PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
      INSERT {
        GRAPH ${targetGraph} {
          ?subject ?predicate ?object .
        }
      }
      WHERE {
        SERVICE <http://cambridgesemantics.com/services/DataToolkit> {
          GRAPH <http://cambridgesemantics.com/Layer/698d179498f945a393f8a91ee9f1f611/Model> {
            <http://cambridgesemantics.com/Layer/698d179498f945a393f8a91ee9f1f611/Model#GoodReads100kBooks.FirstPrint> a owl:DatatypeProperty;
            rdfs:comment "Date the book first went to print" ;
            rdfs:label "First Print Date" ;
            rdfs:domain <http://cambridgesemantics.com/Layer/698d179498f945a393f8a91ee9f1f611/Model#GoodReads100kBooks> ;
            rdfs:range xsd:date .
        }
          []
            s:segment "false"^^xsd:boolean .
          ?generator a s:RdfGenerator, s:OntologyGenerator ;
            s:as (?subject ?predicate ?object) ;
            s:base ${targetGraph} .
       
          good_reads_books_files:GoodReads_100k_books a s:FileSource ;
            s:url "/nfs/data/csv/GoodReads_100k_books.csv" ;
            s:model "GoodReads_100k_books" ;
            s:key ("Isbn") .
        }
      }
  6. Save the step and then refresh or reload the graphmart or layer to update the model with the new properties.

For more information about Direct Load Steps, see Directly Load a Data Source (Direct Load Step).