Skip to content

Commit

Permalink
删除错误函数名createRdfResource
Browse files Browse the repository at this point in the history
  • Loading branch information
na57 committed May 22, 2024
1 parent 7a18830 commit b96622d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nagu-owl",
"version": "1.11.1",
"version": "1.11.3",
"description": "[![Node.js CI](https://github.com/nagucc/owl/actions/workflows/node.js.yml/badge.svg)](https://github.com/nagucc/owl/actions/workflows/node.js.yml)",
"type": "module",
"main": "dist/index.js",
Expand Down Expand Up @@ -40,7 +40,7 @@
"typedoc": "^0.25.11"
},
"dependencies": {
"nagu-owl-types": "^1.1.1",
"nagu-owl-types": "^1.2.0",
"nagu-triples": "^2.0.5",
"nagu-triples-types": "^1.0.2"
},
Expand Down
45 changes: 26 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ import triples from 'nagu-triples';
import { Notion } from 'nagu-triples/dist/notions';
import { rdf, rdfs } from './constants';
import { INotion, ITriple } from 'nagu-triples-types';
import { IAnnotations, IRdfProperty, IRdfsClass, IRdfsResource } from 'nagu-owl-types';
import { AnnotationProps, IRdfProperty, IRdfsClass, IRdfsResource } from 'nagu-owl-types';

export class Factory {
options: any;
constructor(options) {
this.options = options;
}
async createRdfResource (uri: INotion<string>|string, forceInit: boolean = true) {
const res = new RdfsResource(uri, this.options);
if (forceInit) await res.init();
return res;
}
async createRdfsResource (uri: INotion<string>|string, forceInit: boolean = true) {
const res = new RdfsResource(uri, this.options);
if (forceInit) await res.init();
Expand Down Expand Up @@ -133,42 +128,54 @@ export class RdfsResource extends Notion<string> implements IRdfsResource {

label: string|Notion<string>;
comment: string|Notion<string>;
isDefinedBy: string|Notion<string>;
isDefinedBy: string|Notion<string>|IRdfsResource;
seeAlso: string|Notion<string>;
/**
* 删除原值后添加新值
*/
async setAnnotations({ label, comment, isDefinedBy, seeAlso }): Promise<void> {
async setAnnotations(annotations: AnnotationProps): Promise<void> {
const { label, comment, isDefinedBy, seeAlso } = annotations;
const operations = [];
// 删除原值
if (this.label) operations.push(this.removePropertyValue(rdfs.label, this.label));
if (this.comment) operations.push(this.removePropertyValue(rdfs.comment, this.comment));
if (this.isDefinedBy) operations.push(this.removePropertyValue(rdfs.isDefinedBy, this.isDefinedBy));
if (this.isDefinedBy) operations.push(this.removePropertyValue(rdfs.isDefinedBy, this.isDefinedBy as INotion<string>));
if (this.seeAlso) operations.push(this.removePropertyValue(rdfs.seeAlso, this.seeAlso));
await Promise.all(operations);

// 设置新值
const setOps = []
if (label) setOps.push(this.setPropertyValue(rdfs.label, label));
if (comment) setOps.push(this.setPropertyValue(rdfs.comment, comment));
if (isDefinedBy) setOps.push(this.setPropertyValue(rdfs.isDefinedBy, isDefinedBy));
if (seeAlso) setOps.push(this.setPropertyValue(rdfs.seeAlso, seeAlso));
const ts = await Promise.all(setOps);
const ts = await Promise.all([
this.setPropertyValue(rdfs.label, label),
this.setPropertyValue(rdfs.comment, comment),
this.setPropertyValue(rdfs.isDefinedBy, isDefinedBy as INotion<string>),
this.setPropertyValue(rdfs.seeAlso, seeAlso),
]);

// 修改自身变量
this.label = ts[0]?.object;
this.comment = ts[1]?.object;
this.isDefinedBy = ts[2]?.object;
this.seeAlso = ts[3]?.object;

// 设置isDefinedBy字段
const isDefinedByResource = new RdfsResource(ts[2]?.object, this.options);
await isDefinedByResource.getAnnotations();
this.isDefinedBy = isDefinedByResource;
}
async getAnnotations(): Promise<IAnnotations> {
const [labels, comments, isDefinedBy, seeAlsos] = await Promise.all([
async getAnnotations(): Promise<AnnotationProps> {
const [labels, comments, isDefinedBys, seeAlsos] = await Promise.all([
rdfs.label, rdfs.comment, rdfs.isDefinedBy, rdfs.seeAlso,
].map(p => this.getPropertyValues(p)));
this.label = (labels || [])[0]?.toString() || '';
this.comment = (comments || [])[0]?.toString() || '';
this.isDefinedBy = (isDefinedBy || [])[0]?.toString() || '';
this.seeAlso = (seeAlsos || [])[0]?.toString() || '';

// 设置isDefinedBy字段
const isDefinedByIRI = (isDefinedBys || [])[0]?.toString() || '';
if (isDefinedByIRI) {
const isDefinedByResource = new RdfsResource(isDefinedByIRI, this.options);
await isDefinedByResource.getAnnotations();
this.isDefinedBy = isDefinedByResource;
}
return this;
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1632,10 +1632,10 @@ mysql2@^3.9.7:
seq-queue "^0.0.5"
sqlstring "^2.3.2"

nagu-owl-types@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/nagu-owl-types/-/nagu-owl-types-1.1.1.tgz"
integrity sha512-lBU015q3CQkFeJ+ED9B6T0hre7Sgcdld92L94SRHlaSom1cdVm+eD1hf8bMZAit0YkLjz9b6t9xGY2ecnoVbeQ==
nagu-owl-types@^1.2.0:
version "1.2.0"
resolved "https://registry.npmjs.org/nagu-owl-types/-/nagu-owl-types-1.2.0.tgz"
integrity sha512-xQI7EZPQJYqYpT/cJNM0CFz/YRgvQpFiCC0wm8cYlVuysIJDxcnizVot54aoQoLWqfqKRml0mpaTUAqvmQe2QA==
dependencies:
nagu-triples-types "^1.0.2"

Expand Down

0 comments on commit b96622d

Please sign in to comment.