Skip to content

Commit

Permalink
add PUT /class/:iri
Browse files Browse the repository at this point in the history
  • Loading branch information
na57 committed May 21, 2024
1 parent 76bfdd4 commit a2dfac7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 90 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "triples-api",
"version": "1.4.9",
"version": "1.5.0",
"description": "对triples进行操作的Restful API",
"main": "index.js",
"type": "module",
Expand Down
56 changes: 4 additions & 52 deletions src/rdf/class.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/**
* 管理rdf:Resource
* 管理rdfs:Class
*/

import express from 'express';
import { Factory, RdfsClass, RdfsResource } from 'nagu-owl';
import { options } from '../utils.ts';
import { setAnnotations } from './resource.ts';
const router = express.Router();
const factory = new Factory(options);

Expand Down Expand Up @@ -43,65 +44,16 @@ const getInstances = async (_req: any, res: {
seeAlso: t.seeAlso,
})),
}

// const [ labels, comments, seeAlsos, types ] = await Promise.all([
// rdfs.label, rdfs.comment, rdfs.seeAlso, rdf.type,
// ].map(p => resource.getPropertyValues(p)));
// return {
// iri: resource.iri.toString(),
// labels: labels.map(l => l.toString()),
// label: (labels || [])[0]?.toString() || '',
// comments: comments.map(l => l.toString()),
// comment: (comments || [])[0]?.toString() || '',
// seeAlsos: seeAlsos.map(l => l.toString()),
// seeAlso: (seeAlsos || [])[0]?.toString() || '',
// types: types.map(l => l.toString()),
// };
};
const data = await Promise.all(resources.map(r => getCommonPvs(r)));
// const data = await Promise.all(resources.map(r => r.getAnnotations()));

res.json({
data,
});
}

// const setCommonPropertyValues = async (req, res) => {
// const { label, comment, seeAlso } = req.body;
// const operations = [
// { iri: RDFS.terms.label, value: label },
// { iri: RDFS.terms.comment, value: comment },
// { iri: RDFS.terms.seeAlso, value: seeAlso },
// ].map(async p => {
// if (!p.value) return null;
// return res.resource.setPropertyValues(p.iri, p.value);
// });
// await Promise.all(operations);
// res.json({
// data: {
// iri: res.resource.uri,
// label,
// comment,
// seeAlso,
// },
// });
// }

// const removeCommonPropertyValues = async (_req: any, res: { resource: RdfsResource; }, next: () => void) => {
// const operations = [
// RDFS.terms.label,
// RDFS.terms.comment,
// RDFS.terms.seeAlso,
// ].map(async p => {
// // 获取原值
// const os = await res.resource.getPropertyValues(p);
// // 删除原值
// await Promise.all(os.map(o => res.resource.removePropertyValue(p, o)));
// });
// next();
// }


router.get('/:iri/instances', getOrCreateClass, getInstances);
// router.put('/:iri', getOrCreateResource, setCommonPropertyValues);
// router.post('/:iri', getOrCreateResource, removeCommonPropertyValues, setCommonPropertyValues);
router.put('/:iri', getOrCreateClass, setAnnotations);
export default router;
40 changes: 3 additions & 37 deletions src/rdf/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import express from 'express';
import { Factory, RDF, RDFS, RdfsResource } from 'nagu-owl';
import { Factory, RdfsResource } from 'nagu-owl';
import { options } from '../utils.ts';

const router = express.Router();
Expand All @@ -24,14 +24,6 @@ const getOrCreateResource = async (req ,res, next) => {
const getAnnotations = async (req, res: {
json: any; resource: RdfsResource
}) => {
// const operations = [
// RDFS.terms.label,
// RDFS.terms.comment,
// RDFS.terms.seeAlso,
// ].map(async p => {
// // 获取原值
// const os = await res.resource.getPropertyValues(await factory.createRdfProperty(p));
// });
await res.resource.getAnnotations();
const { iri, label, comment, seeAlso } = res.resource;
res.json({
Expand All @@ -46,43 +38,17 @@ const getAnnotations = async (req, res: {
export const setAnnotations = async (req, res: {
json: any; resource: RdfsResource
}) => {
// const { label, comment, seeAlso } = req.body;
await res.resource.setAnnotations(req.body);
// const operations = [
// { iri: RDFS.terms.label, value: label },
// { iri: RDFS.terms.comment, value: comment },
// { iri: RDFS.terms.seeAlso, value: seeAlso },
// ].map(async p => {
// if (!p.value) return null;
// return res.resource.setPropertyValues(p.iri, p.value);
// });
// await Promise.all(operations);
const { iri } = res.resource;
res.json({
data: {
iri,
// label,
// comment,
// seeAlso,
...req.body,
},
});
}

// export const removeCommonPropertyValues = async (_req: any, res: { resource: RdfsResource; }, next: () => void) => {
// const operations = [
// RDFS.terms.label,
// RDFS.terms.comment,
// RDFS.terms.seeAlso,
// ].map(async p => {
// // 获取原值
// const os = await res.resource.getPropertyValues(p);
// // 删除原值
// await Promise.all(os.map(o => res.resource.removePropertyValue(p, o)));
// });
// next();
// }

router.get('/:iri', getOrCreateResource, getAnnotations);
router.put('/:iri', getOrCreateResource, setAnnotations);
router.post('/:iri', getOrCreateResource, /*removeCommonPropertyValues,*/ setAnnotations);
router.post('/:iri', getOrCreateResource, setAnnotations);
export default router;

0 comments on commit a2dfac7

Please sign in to comment.