UNPKG

schema-dts-gen

Version:

Generate TypeScript Definitions for Schema.org Schema

34 lines 1.31 kB
import { shortStr } from '../index.js'; import { Log } from '../logging/index.js'; import { IsPropertyType } from '../triples/wellKnown.js'; import { PropertyType } from '../ts/property.js'; import { assertIs } from '../util/assert.js'; /** * Annotates classes with any Property values they blong to. * * @param topics a sequence of processed triples describing an Ontology. * @param classes return value of `ProcessClasses`. */ export function ProcessProperties(topics, classes) { for (const topic of topics) { // Skip Topics that have no 'Property' Type. if (!topic.types.some(IsPropertyType)) continue; const rest = []; assertIs(topic.subject, (s) => s.termType === 'NamedNode'); const property = new PropertyType(topic.subject); for (const value of topic.quads) { const added = property.add(value, classes); if (!added) { rest.push(value); } } // Go over RangeIncludes or DomainIncludes: if (rest.length > 0) { Log(`Still unadded for property: ${shortStr(topic.subject)}:\n\t${rest .map(q => `(${shortStr(q.predicate)} ${shortStr(q.object)})`) .join('\n\t')}`); } } } //# sourceMappingURL=toProperty.js.map