Class SchemaDocument
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
ConstructorsConstructorDescriptionSchemaDocument(File source) 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 TypeMethodDescriptionCollection<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.SlotDefinitiongetAttribute(String className, String attrName) Gets the definition of the specified attribute within a class.org.incenp.linkml.schema.model.ClassDefinitiongetClassDefinition(String name) Gets the definition of the specified class.org.incenp.linkml.schema.model.EnumDefinitionGets 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.SchemaDefinitionGets the top-level schema.org.incenp.linkml.schema.model.SlotDefinitionGets the definition of the specified slot.org.incenp.linkml.schema.model.SlotDefinitiongetSlotUsage(String className, String slotName) Gets the definition of the specified slot usage within a class.org.incenp.linkml.schema.model.TypeDefinitionGets the definition of the specified type.
-
Constructor Details
-
SchemaDocument
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
Gets the schemas that are (directly or not) imported by the top-level schema. -
getAllClasses
Gets all classes defined across the top-level schema and all imported schemas. -
getAllSlots
Gets all slots defined across the top-level schema and all imported schemas. -
getAllEnums
Gets all enums defined across the top-level schema and all imported schemas. -
getAllTypes
Gets all types defined across the top-level schema and all imported schemas. -
getClassDefinition
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
nullif there is no class with that name.
-
getSlot
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
nullif there is no slot with that name.
-
getEnum
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
nullif there is no enum with that name.
-
getType
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
nullif 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
nullif 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
nullif there is no class with the indicated name or the class has no slot usage definition with such a name.
-