Skip to content

Commit

Permalink
Experimental OFN conversion support
Browse files Browse the repository at this point in the history
  • Loading branch information
bindeali committed Nov 7, 2024
1 parent 9d43cd2 commit a65eca6
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
94 changes: 94 additions & 0 deletions src/interface/OFNInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import isUrl from "is-url";
import { Representation } from "../config/Enum";
import { LanguageObject } from "../config/Languages";
import { RepresentationConfig } from "../config/logic/RepresentationConfig";
import { Prefixes, WorkspaceElements, WorkspaceLinks, WorkspaceTerms, WorkspaceVocabularies } from "../config/Variables";
import { parsePrefix } from "../function/FunctionEditVars";
import { getParentOfIntrinsicTropeType } from "../function/FunctionGetVars";
import { qb } from "../queries/QueryBuilder";

export function dumpOFNVocabularies() {
const addStatement = (s: string, p: string, o: string, option?: boolean) => qb.s(s, p, o, option) + (option ? " \n" : "")
const mapLanguageObject = (lo: LanguageObject) => Object.keys(lo).filter((l) => lo[l]).map((l) => qb.ll(lo[l], l))

for (const vocabulary in WorkspaceVocabularies) {
if (WorkspaceVocabularies[vocabulary].readOnly) continue;
const vocabularyTerms = Object.keys(WorkspaceTerms).filter(t => WorkspaceElements[t].vocabulary === vocabulary)
if (vocabularyTerms.length === 0) continue;
let vExport = "";
// Prefixes
Object.entries(Prefixes).forEach(([k, v]) => vExport += `@prefix ${k}: ${qb.i(v)}. \n`)
// Vocabulary info
// Type
if (vocabularyTerms.find(t => WorkspaceTerms[t].types.includes(parsePrefix("z-sgov-pojem", "typ-vlastnosti")) || WorkspaceTerms[t].types.includes(parsePrefix("z-sgov-pojem", "typ-vztahu"))))
vExport += addStatement(qb.i(vocabulary), "rdf:type", "owl:Ontology")
else
vExport += addStatement(qb.i(vocabulary), "rdf:type", "skos:ConceptScheme")
// Name
const vocabularyNames = mapLanguageObject(WorkspaceVocabularies[vocabulary].labels)
vExport += addStatement(qb.i(vocabulary), "skos:prefLabel", qb.a(vocabularyNames), vocabularyNames.length > 0)
// Terms
for (const term of vocabularyTerms) {
let tExport = "";
// Type
const termType = WorkspaceTerms[term].types.filter(t => RepresentationConfig[Representation.FULL].visibleStereotypes.includes(t))
if (termType.includes(parsePrefix("z-sgov-pojem", "typ-objektu"))) {
tExport += addStatement(qb.i(term), "rdf:type", "owl:Class");
// Subclass
for (const subClass of WorkspaceTerms[term].subClassOf) {
tExport += addStatement(qb.i(term), "rdfs:subClassOf", qb.i(subClass))
}
} else if (termType.includes(parsePrefix("z-sgov-pojem", "typ-vlastnosti"))) {
const tropeDomain = getParentOfIntrinsicTropeType(term);
if (tropeDomain.length !== 1) {
console.warn(`Corresponding object type to trope ${term} not found.`);
continue;
}
tExport += addStatement(qb.i(term), "rdf:type", "owl:DatatypeProperty");
// Subclass
for (const subClass of WorkspaceTerms[term].subClassOf) {
tExport += addStatement(qb.i(term), "rdfs:subPropertyOf", qb.i(subClass))
}
// Domain
tExport += addStatement(qb.i(term), "rdfs:domain", qb.i(tropeDomain[0]))
} else if (termType.includes(parsePrefix("z-sgov-pojem", "typ-vztahu"))) {
const linkID = Object.keys(WorkspaceLinks).find(id => WorkspaceLinks[id].iri === term)
if (!linkID) {
console.warn(`Corresponding link ID to ${term} not found.`);
continue;
}
tExport += addStatement(qb.i(term), "rdf:type", "owl:ObjectProperty");
// Subclass
for (const subClass of WorkspaceTerms[term].subClassOf) {
tExport += addStatement(qb.i(term), "rdfs:subPropertyOf", qb.i(subClass))
}
// Domain
tExport += addStatement(qb.i(term), "rdfs:domain", qb.i(WorkspaceLinks[linkID].source))
// Range
tExport += addStatement(qb.i(term), "rdfs:range", qb.i(WorkspaceLinks[linkID].target))
} else {
console.warn(`${term} not recognized as a valid term.`)
continue;
}
// Scheme
tExport += addStatement(qb.i(term), "skos:inScheme", qb.i(vocabulary))
// Name
const termNames = mapLanguageObject(WorkspaceTerms[term].labels);
tExport += addStatement(qb.i(term), "skos:prefLabel", qb.a(termNames), termNames.length > 0)
// Description
const termDescriptions = mapLanguageObject(WorkspaceTerms[term].descriptions);
tExport += addStatement(qb.i(term), "dc:description", qb.a(termDescriptions), termDescriptions.length > 0)
// Definition
const termDefinitions = mapLanguageObject(WorkspaceTerms[term].definitions);
tExport += addStatement(qb.i(term), "skos:definition", qb.a(termDefinitions), termDefinitions.length > 0)
// Source
if (isUrl(WorkspaceTerms[term].source))
tExport += addStatement(qb.i(term), "dc:conformsTo", qb.i(WorkspaceTerms[term].source))
else if (!!!WorkspaceTerms[term].source)
tExport += addStatement(qb.i(term), "dc:conformsTo", qb.ll(WorkspaceTerms[term].source))

vExport += tExport;
}
console.log(vExport)
}
}
2 changes: 2 additions & 0 deletions src/main/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
} from "../queries/update/UpdateDiagramQueries";
import { MainView } from "./MainView";
import { ToastService } from "./ToastService";
import { dumpOFNVocabularies } from "../interface/OFNInterface";

interface DiagramAppProps {}

Expand Down Expand Up @@ -158,6 +159,7 @@ export default class App extends React.Component<
componentDidMount(): void {
const finishUp = () => {
hotkeys("ctrl+alt+d", () => dumpDebugData());
hotkeys("ctrl+alt+s", () => dumpOFNVocabularies())
checkForObsoleteDiagrams();
this.handleChangeLanguage(AppSettings.canvasLanguage);
setSchemeColors(AppSettings.viewColorPool);
Expand Down

0 comments on commit a65eca6

Please sign in to comment.