Skip to main content

Defining a Domain Using DomainDefinition

Defining a Domain Using DomainDefinition

When a user creates and compiles a class inheriting from %iKnow.DomainDefinitionOpens in a new tab, the compiler will automatically create an InterSystems NLP domain corresponding to the settings specified in XML representation in the class’s Domain XData block. The user can specify static elements, such as domain parameters, metadata field definitions, and an assigned Configuration, all of which are created automatically at compile time. In addition, the user can specify sources of text data to be loaded into the domain. InterSystems IRIS uses this source information to generate a dedicated %Build() method in a new class named [classname].Domain. This %Build() method can then be used to load the specified data into the domain.

The following is an example of this kind of domain definition:

Class Aviation.MyDomain Extends %iKnow.DomainDefinition
{
/// An XML representation of the domain this class defines.
XData Domain [ XMLNamespace = "http://www.intersystems.com/iknow" ]
 {
 <domain name="AviationEvents">
   <parameter name="Status" value="1" />
   <configuration name="MyConfig" detectLanguage="1" languages="en,es" />
   <parameter name="DefaultConfig" value="MyConfig" />
   <metadata> 
     <field name="EventDate" dataType="DATE"/>
        <field name="Type" dataType="STRING" /> 
   </metadata>
  <data dropBeforeBuild="true">
    <files path="C:\MyDocs\" encoding="utf-8" recursive="1" extensions="txt"
       configuration="MyConfig" />
     <query sql="SELECT %ID,EventDate,Type,NarrativeFull
                    FROM Aviation.Event"
                    idField="ID" groupField="ID" dataFields="NarrativeFull"
      metadataFields="EventDate,Type" metadataColumns="EventDate,Type" />
   </data>
  </domain>
  }
 } 

At compile-time, this definition creates a domain "AviationEvents", with a Status parameter set to 1, and two metadata fields. It defines and assigns to the domain a Configuration "MyConfig" for processing English (en) and Spanish (es) texts.

This definition specifies the files to be loaded into this domain. It will load text (.txt) files from the C:\MyDocs\ directory, and it will load InterSystems SQL data from the Aviation.Event table. Refer to the %iKnow.Model.listFilesOpens in a new tab and %iKnow.Model.listQueryOpens in a new tab class properties for details.

The system generates a %Build()Opens in a new tab method in a dependent class named Aviation.MyDomain.Domain that contains the logic to load data from the C:\MyDocs directory and the Aviation.Event table.

To load the specified text data sources into this domain:

  SET stat=##class(Aviation.MyDomain).%Build()

After using %Build(), you can check for errors:

  DO $SYSTEM.iKnow.ListErrors("AviationEvents",0)

This lists three types of errors: errors, failed sources, and warnings.

To display the domains defined in the current namespace and the number of sources loaded for each domain:

  DO $SYSTEM.iKnow.ListDomains() 

To display the metadata fields defined for this domain:

  DO $SYSTEM.iKnow.ListMetadata("AviationEvents")

InterSystems NLP assigns every domain one metadata field: DateIndexed. You can define additional metadata fields.

You can specify a <matching> element in the domain definition. The <matching> element describes dictionary information and specifies whether or not to automatically match loaded sources to these dictionaries. InterSystems IRIS performs basic validation on these objects during class compilation, but because they are loaded as part of the %Build() method, some name conflicts might only arise at runtime. Refer to the %iKnow.Model.matchingOpens in a new tab class properties for details.

You can specify a <metrics> element in the domain definition. The <metrics> element adds custom metrics to the domain. No call to %iKnow.Metrics.MetricDefinition.Register() is required, because this is automatically performed by the Domain Definition code at compile time. Refer to the %iKnow.Model.metricsOpens in a new tab class properties for details.

FeedbackOpens in a new tab