-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Convenience Methods to Ontology Information (#265)
* refactor (ontology utils): make utility method to filter property defs * feature (ontology): add helper methods for class defs * refactor (ontology utils): make util methods generic * refactor (ontology): make interface an abstract class * tests (ontologies): add more assertions * docs (ontologies): use @category tag
- Loading branch information
1 parent
fc1c086
commit 31a3044
Showing
6 changed files
with
108 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { TypeGuard } from "../resources/type-guard"; | ||
import { ClassDefinition } from "./class-definition"; | ||
import { EntityDefinition } from "./EntityDefinition"; | ||
import { PropertyDefinition } from "./property-definition"; | ||
|
||
/** | ||
* @category Internal | ||
*/ | ||
export abstract class ClassAndPropertyDefinitions { | ||
|
||
abstract properties: { [index: string]: PropertyDefinition }; | ||
abstract classes: { [index: string]: ClassDefinition }; | ||
|
||
abstract getAllPropertyDefinitions(): PropertyDefinition[]; | ||
abstract getPropertyDefinitionsByType<T extends PropertyDefinition>(type: TypeGuard.Constructor<T>): T[]; | ||
|
||
/** | ||
* Given a map of entity Iris to entity definitions, | ||
* returns an array of entity definitions. | ||
* | ||
* @param entityDefs Entity definitions to be returned as an array. | ||
*/ | ||
protected getAllEntityDefinitionsAsArray<T extends EntityDefinition>(entityDefs: { [ index: string ]: T } ): T[] { | ||
const entityIndexes = Object.keys(entityDefs); | ||
|
||
return entityIndexes.map((entityIndex: string) => { | ||
return entityDefs[entityIndex]; | ||
}); | ||
} | ||
|
||
/** | ||
* Given an array of entity definitions, | ||
* returns only the entity definitions matching the given type. | ||
* | ||
* @param entityDefs The entity definitions to be filtered. | ||
* @param type The type of entity definitions to be returned. | ||
*/ | ||
protected getEntityDefinitionsByTypeAsArray<T extends EntityDefinition>(entityDefs: EntityDefinition[], type: TypeGuard.Constructor<T>): T[] { | ||
return entityDefs.filter( | ||
(entityDef: EntityDefinition) => { | ||
return TypeGuard.typeGuard(entityDef, type); | ||
}) as T[]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters