Skip to main content
Version: Next

Projects & packages

Everything in ontouml-js lives inside a Project, and every model element lives inside a Package. Before we get to classes and relations, let's look at these containers — because they're also how you create everything else.

Theory: what's a package for?

A package is just a named grouping of model elements. Large ontologies are split into packages by sub-domain (people, products, payments…) exactly as you'd split code into modules. One package per project is the root ("model") package; all others nest inside it.

Creating a project​

There are two equivalent ways. Use the constructor for quick work:

import { class Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const project: Projectproject.NamedElement.name: LanguageString
The name of this element, possibly in multiple languages.
name
.LanguageString.add(value: string, language?: string): void
Adds a text value in the given language, replacing any existing value for that language.
@paramvalue - the text to add.@paramlanguage - language tag of `value`; defaults to defaultLanguage.@throwsan error if `language` is not a valid language tag.
add
('Library domain');

Or the fluent ProjectBuilder when you want to set catalog metadata (publisher, license, keywords) at creation time:

import { class ProjectBuilder
A fluent builder for Project instances. In addition to the identification and naming methods inherited from NamedElementBuilder , this builder supports the project-level metadata fields prescribed by the OntoUML/UFO catalog metadata schema, such as publisher, license, keywords, and designed-for tasks.
@example```typescript const project = new ProjectBuilder() .name('UFO-S') .keyword('services', 'en') .language('en') .license('https://creativecommons.org/licenses/by/4.0/') .build(); ```
ProjectBuilder
} from 'ontouml-js';
const const project: Projectproject = new new ProjectBuilder(): ProjectBuilder
A fluent builder for Project instances. In addition to the identification and naming methods inherited from NamedElementBuilder , this builder supports the project-level metadata fields prescribed by the OntoUML/UFO catalog metadata schema, such as publisher, license, keywords, and designed-for tasks.
@example```typescript const project = new ProjectBuilder() .name('UFO-S') .keyword('services', 'en') .language('en') .license('https://creativecommons.org/licenses/by/4.0/') .build(); ```
ProjectBuilder
()
.NamedElementBuilder<ProjectBuilder>.name(value: string, language?: string): ProjectBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Library domain')
.ProjectBuilder.keyword(value: string, language?: string): ProjectBuilder
Adds a keyword describing the content of the project.
@paramvalue - the keyword text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
keyword
('libraries')
.ProjectBuilder.language(value: string): ProjectBuilder
Adds a language in which the project's elements are written, identified by a language tag (e.g., `"en"`, `"pt"`).
@returnsthis builder, for method chaining.
language
('en')
.ProjectBuilder.license(uri?: string, name?: string, language?: string): ProjectBuilder
Sets the license under which the project is distributed.
@paramuri - URI identifying the license (e.g., `"https://creativecommons.org/licenses/by/4.0/"`).@paramname - human-readable label of the license (e.g., `"CC BY 4.0"`).@paramlanguage - language tag of `name` (e.g., `"en"`).@returnsthis builder, for method chaining.@throwsan error if both `uri` and `name` are absent.
license
('https://creativecommons.org/licenses/by/4.0/')
.ProjectBuilder.build(): Project
Builds an instance of Project with the parameters passed to the builder. When no methods are evoked, the created project has the following defaults: - `id: "randomly-generated-id",` - `created: new Date()`
@throwsan error if the builder has already been used.
build
();

The root package, and nesting​

A project's elements hang off a single root package. Create it with .root(), then nest sub-packages inside it. Remember: a package is a factory for its contents, so you build classes and sub-packages from the package they belong to.

import { class Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
} from 'ontouml-js';
const const project: Projectproject = new new Project(): Project
An OntoUML project: the top-level container of an ontology and the entry point of this library. A project holds every element of a model — classes, relations, generalizations, packages, properties, notes — as well as the diagrams and views that depict them, and provides typed access to these elements by id or by kind. New elements are created through the fluent builders exposed by the project (e.g., classBuilder , binaryRelationBuilder ), which register the created elements in the project. A project is also described by the metadata fields of the OntoUML/UFO Catalog Metadata Vocabulary, such as publisher, license, keywords, themes, and designed-for tasks.
@example```typescript const project = new Project(); const person = project.classBuilder().kind().name('Person').build(); const student = project.classBuilder().role().name('Student').build(); project .generalizationBuilder() .general(person) .specific(student) .build(); ```
Project
();
const project: Projectproject.NamedElement.name: LanguageString
The name of this element, possibly in multiple languages.
name
.LanguageString.add(value: string, language?: string): void
Adds a text value in the given language, replacing any existing value for that language.
@paramvalue - the text to add.@paramlanguage - language tag of `value`; defaults to defaultLanguage.@throwsan error if `language` is not a valid language tag.
add
('Library domain');
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilder
Creates a builder for a new Package in this project.
packageBuilder
().PackageBuilder.root(): PackageBuilder
Sets the package as the root package of its project, i.e., the package that contains the entire model.
@returnsthis builder, for method chaining.
root
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Model').PackageBuilder.build(): Package
Builds an instance of Package with the parameters passed to the builder. When no methods are evoked, the created package has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `contents: []`
@throwsan error if the builder has already been used.
build
();
const const people: Packagepeople = const model: Packagemodel.Package.packageBuilder(): PackageBuilder
Creates a builder for a Package contained in this package.
packageBuilder
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('People').PackageBuilder.build(): Package
Builds an instance of Package with the parameters passed to the builder. When no methods are evoked, the created package has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `contents: []`
@throwsan error if the builder has already been used.
build
();
const const catalog: Packagecatalog = const model: Packagemodel.Package.packageBuilder(): PackageBuilder
Creates a builder for a Package contained in this package.
packageBuilder
().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Catalog').PackageBuilder.build(): Package
Builds an instance of Package with the parameters passed to the builder. When no methods are evoked, the created package has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `contents: []`
@throwsan error if the builder has already been used.
build
();
const people: Packagepeople.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets the stereotype of the class to «kind», which decorates rigid classes that provide an identity principle to their instances, which are functional complexes (e.g., `Person`, `Car`). Also applies the following defaults: - `restrictedTo = [ "functional-complex" ]` - `order = 1`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Person').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const people: Packagepeople.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets the stereotype of the class to «kind», which decorates rigid classes that provide an identity principle to their instances, which are functional complexes (e.g., `Person`, `Car`). Also applies the following defaults: - `restrictedTo = [ "functional-complex" ]` - `order = 1`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Librarian').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const catalog: Packagecatalog.Package.classBuilder(): ClassBuilder
Creates a builder for a Class contained in this package.
classBuilder
().ClassBuilder.kind(): ClassBuilder
Sets the stereotype of the class to «kind», which decorates rigid classes that provide an identity principle to their instances, which are functional complexes (e.g., `Person`, `Car`). Also applies the following defaults: - `restrictedTo = [ "functional-complex" ]` - `order = 1`
@returnsthis builder, for method chaining.
kind
().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilder
Adds a name to the element in the given language.
@paramvalue - the name text.@paramlanguage - language tag of `value`; defaults to LanguageString.defaultLanguage.@returnsthis builder, for method chaining.
name
('Book').ClassBuilder.build(): Class
Builds an instance of Class with the parameters passed to the builder. **WARNING:** the ordering in which methods are evoked may affect the resulting object. When no methods are evoked, the created class has the following defaults: - `id: "randomly-generated-id",` - `created: new Date(),` - `isAbstract: false,` - `isDerived: false,` - `order: 1,` - `isPowertype: false,`
@throwsan error if the builder has already been used.
build
();
const const allClasses: Class[]allClasses = const project: Projectproject.Project.classes: Class[]
The classes contained in this project.
classes
;
const const peopleClasses: Class[]peopleClasses = const people: Packagepeople.Package.classes: Class[]
The classes directly contained in this package.
classes
;
var console: Consoleconsole.Console.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(const allClasses: Class[]allClasses.Array<Class>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
length
); // 3
var console: Consoleconsole.Console.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
log
(const peopleClasses: Class[]peopleClasses.Array<Class>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
length
); // 2

Hover allClasses above: the project's classes getter walks every nested package for you, so you rarely need to traverse the tree by hand. We'll go deeper on reading a model back in the Querying chapter.

Key takeaways​

  • A Project is the root; it holds exactly one root Package.
  • Packages nest and group elements by sub-domain.
  • A container is a factory — build contents from the package they live in, and their container is wired up for you.
  • project.classes (and friends) query across the whole containment tree.

Next: classes & stereotypes →, where the modeling really begins.