Class SchemaDocument

java.lang.Object
org.incenp.linkml.schema.SchemaDocument

public class SchemaDocument extends Object
Represents an entire LinkML schema. This is the primary interface to parse a LinkML schema.

While a LinkML schema could in principle be parsed as follows:

ObjectLoader loader = new ObjectLoader();
SchemaDefinition schema = load.loadObject(new File("schema.yaml"), SchemaDefinition.class);

this would not take into account some aspects of a LinkML schema. In particular, this would ignore imports, which are a concept that is specific to LinkML’s meta-model and that is not itself described in LinkML.

Loading a schema using this class will ensure that all imports are in fact imported, and will therefore provide a view of the true entire schema.

This class also provides helper methods to look up the various elements that make up a schema.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance from the specified file.
    SchemaDocument(File source, ISchemaResolver importResolver)
    Creates a new instance from the specified file, using a custom import resolver.
    SchemaDocument(ISchemaSource source, ISchemaResolver importResolver)
    Creates a new instance from the specified source, using a custom import resolver.
  • Method Summary

    Modifier and Type
    Method
    Description
    Collection<org.incenp.linkml.schema.model.ClassDefinition>
    Gets all classes defined across the top-level schema and all imported schemas.
    Collection<org.incenp.linkml.schema.model.EnumDefinition>
    Gets all enums defined across the top-level schema and all imported schemas.
    Collection<org.incenp.linkml.schema.model.SlotDefinition>
    Gets all slots defined across the top-level schema and all imported schemas.
    Collection<org.incenp.linkml.schema.model.TypeDefinition>
    Gets all types defined across the top-level schema and all imported schemas.
    org.incenp.linkml.schema.model.SlotDefinition
    getAttribute(String className, String attrName)
    Gets the definition of the specified attribute within a class.
    org.incenp.linkml.schema.model.ClassDefinition
    Gets the definition of the specified class.
    org.incenp.linkml.schema.model.EnumDefinition
    Gets the definition of the specified enum.
    Collection<org.incenp.linkml.schema.model.SchemaDefinition>
    Gets the schemas that are (directly or not) imported by the top-level schema.
    org.incenp.linkml.schema.model.SchemaDefinition
    Gets the top-level schema.
    org.incenp.linkml.schema.model.SlotDefinition
    Gets the definition of the specified slot.
    org.incenp.linkml.schema.model.SlotDefinition
    getSlotUsage(String className, String slotName)
    Gets the definition of the specified slot usage within a class.
    org.incenp.linkml.schema.model.TypeDefinition
    Gets the definition of the specified type.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SchemaDocument

      public SchemaDocument(File source) throws IOException, InvalidSchemaException
      Creates a new instance from the specified file.
      Parameters:
      source - The file from which to parse the LinkML schema.
      Throws:
      IOException - If we cannot read the specified file.
      InvalidSchemaException - If the file is not a valid schema.
    • SchemaDocument

      public SchemaDocument(File source, ISchemaResolver importResolver) throws IOException, InvalidSchemaException
      Creates a new instance from the specified file, using a custom import resolver.
      Parameters:
      source - The source file from which to parse the LinkML schema.
      importResolver - The resolver to use to resolve import names into schema source objects.
      Throws:
      IOException - If we cannot read the specified file.
      InvalidSchemaException - If the file is not a valid schema.
    • SchemaDocument

      public SchemaDocument(ISchemaSource source, ISchemaResolver importResolver) throws IOException, InvalidSchemaException
      Creates a new instance from the specified source, using a custom import resolver.
      Parameters:
      source - The source location from which to obtain the LinkML schema.
      importResolver - The resolver to use to resolve import names into schema source objects.
      Throws:
      IOException - If we cannot read the specified file.
      InvalidSchemaException - If the file is not a valid schema.
  • Method Details

    • getRootSchema

      public org.incenp.linkml.schema.model.SchemaDefinition getRootSchema()
      Gets the top-level schema.

      This is the schema contained directly in the file given to the constructor.

    • getImports

      public Collection<org.incenp.linkml.schema.model.SchemaDefinition> getImports()
      Gets the schemas that are (directly or not) imported by the top-level schema.
    • getAllClasses

      public Collection<org.incenp.linkml.schema.model.ClassDefinition> getAllClasses()
      Gets all classes defined across the top-level schema and all imported schemas.
    • getAllSlots

      public Collection<org.incenp.linkml.schema.model.SlotDefinition> getAllSlots()
      Gets all slots defined across the top-level schema and all imported schemas.
    • getAllEnums

      public Collection<org.incenp.linkml.schema.model.EnumDefinition> getAllEnums()
      Gets all enums defined across the top-level schema and all imported schemas.
    • getAllTypes

      public Collection<org.incenp.linkml.schema.model.TypeDefinition> getAllTypes()
      Gets all types defined across the top-level schema and all imported schemas.
    • getClassDefinition

      public org.incenp.linkml.schema.model.ClassDefinition getClassDefinition(String name)
      Gets the definition of the specified class.

      This looks up the class across the entire imports closure.

      Parameters:
      name - The name of the class.
      Returns:
      The corresponding class definition, or null if there is no class with that name.
    • getSlot

      public org.incenp.linkml.schema.model.SlotDefinition getSlot(String name)
      Gets the definition of the specified slot.

      This looks up the slot across the entire imports closure.

      Parameters:
      name - The name of the slot.
      Returns:
      The corresponding slot definition, or null if there is no slot with that name.
    • getEnum

      public org.incenp.linkml.schema.model.EnumDefinition getEnum(String name)
      Gets the definition of the specified enum.

      This looks up the enum across the entire imports closure.

      Parameters:
      name - The name of the enum.
      Returns:
      The corresponding enum definition, or null if there is no enum with that name.
    • getType

      public org.incenp.linkml.schema.model.TypeDefinition getType(String name)
      Gets the definition of the specified type.

      This looks up the type across the entire imports closure.

      Parameters:
      name - The name of the type.
      Returns:
      The corresponding type definition, or null if there is no type with that name.
    • getAttribute

      public org.incenp.linkml.schema.model.SlotDefinition getAttribute(String className, String attrName)
      Gets the definition of the specified attribute within a class.

      This looks up the the class entire the entire import closure.

      Parameters:
      className - The name of the class.
      attrName - The name of the attribute.
      Returns:
      The corresponding attribute definition, or null if there is no class with the indicated name or the class has no such attribute.
    • getSlotUsage

      public org.incenp.linkml.schema.model.SlotDefinition getSlotUsage(String className, String slotName)
      Gets the definition of the specified slot usage within a class.

      This looks up the class entire the entire import closure.

      Parameters:
      className - The name of the class.
      slotName - The name of the slot.
      Returns:
      The corresponding slot usage definition, or null if there is no class with the indicated name or the class has no slot usage definition with such a name.