Commit 2277745f authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Implementing the FoaF views

parent c0a92e38b3dd
......@@ -25,7 +25,7 @@ import {
NamedNode,
BlankNode,
Literal
} from "rdflib/build/lib";
} from "rdflib";
import { definition, application, implementation } from "@logilab/libview";
import { DEFAULT_DESCRIPTOR_TRIPLES } from "./view-defaults";
......
......@@ -19,7 +19,7 @@
******************************************************************************/
import { definition, application, implementation } from "@logilab/libview";
import { RdfStore, RDF, Term } from "rdflib/build/lib";
import { RdfStore, RDF, Term } from "rdflib";
let _rdf = require("rdflib");
const $rdf: RDF = _rdf;
import React = require("react");
......
{
"name": "@logilab/views-foaf",
"version": "0.1.0",
"description": "Implementation of views for FoaF datasets.",
"scripts": {
"build": "webpack",
"clean": "rm -rf build/*",
"test": "echo \"Error: no test specified\" && exit 1",
"build:production": "NODE_ENV=production webpack",
"serve": "webpack && webpack-dev-server"
},
"main": "./build/index.js",
"types": "./build/lib/index.d.ts",
"repository": {
"type": "hg",
"url": "https://bitbucket.org/laurentw/logilab-cubicweb-client"
},
"keywords": [
"DataBrowser",
"Typescript"
],
"author": "LOGILAB <contact@logilab.fr>",
"license": "LGPL-3.0",
"dependencies": {
"@logilab/libview": "file:../libview",
"@types/node": "^10.5.3",
"@types/rdflib": "file:../rdflib-types",
"rdflib": "^0.17.0",
"vue": "^2.5.16"
},
"devDependencies": {
"copy-webpack-plugin": "^4.5.2",
"source-map-loader": "^0.2.3",
"ts-loader": "^4.4.2",
"typescript": "^2.9.2",
"webpack": "^4.0.1",
"webpack-cli": "^2.0.10",
"webpack-dev-server": "^3.0.0"
}
}
[
{
"identifier": "::Logilab::FoaF::Person",
"name": "FoaF Person",
"description": "Renders a person from a FoaF dataset",
"entrypoint": "VIEW_FOAF_PERSON",
"location": {
"kind": "remote",
"uri": "http://localhost:8080/foaf_person.js"
}
}
]
/*******************************************************************************
* Copyright 2003-2018 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
* contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
*
* This file is part of CubicWeb.
*
* CubicWeb is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 2.1 of the License, or (at your option)
* any later version.
*
* CubicWeb is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
import { definition, application, implementation } from "@logilab/libview";
import { RdfStore, RDF, Term } from "rdflib";
let _rdf = require("rdflib");
const $rdf: RDF = _rdf;
/**
* The descritptor for the default Dbpedia person view
*/
const DESCRIPTOR_PERSON: definition.ViewDescriptor = {
identifier: "::Logilab::FoaF::Person",
name: "FoaF Person",
description: "Renders a person from a FoaF dataset",
entrypoint: "VIEW_FOAF_PERSON",
location: {
kind: definition.ViewLocationKind.Embedded
}
};
/**
* Determines whether the RDF store with the specified primary topic matches a trait:
* Has a primary topic
* @param store The RDF store
* @param primaryTopic The primary topic
*/
function hasTraitHasPrimary(store: RdfStore, primaryTopic: string): boolean {
return primaryTopic != null;
}
/**
* Determines whether the RDF store with the specified primary topic matches a trait:
* The primary topic is a person in DBPedia
* @param store The RDF store
* @param primaryTopic The primary topic
*/
function hasTraitDbPediaPerson(store: RdfStore, primaryTopic: string): boolean {
if (!hasTraitHasPrimary(store, primaryTopic)) return false;
let a = store.each(
$rdf.sym(primaryTopic),
$rdf.sym("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
$rdf.sym("http://dbpedia.org/ontology/Person"),
undefined
);
return a != null && a != undefined && a.length > 0;
}
class FoaFPersonRendering implements implementation.ViewImplementation {
descriptor: definition.ViewDescriptor;
constructor() {
this.descriptor = DESCRIPTOR_PERSON;
this.priorityFor = this.priorityFor.bind(this);
this.render = this.render.bind(this);
}
priorityFor(store: RdfStore, target: string): number {
return hasTraitDbPediaPerson(store, target) ? 10 : -1;
}
render(
renderer: application.ViewRenderer,
store: RdfStore,
root: string,
target: string
): HTMLElement {
let result = document.createElement("div");
return result;
}
}
/**
* Gets the value for the propert of a resource
* @param store The RDF store containing the data
* @param resource The resource
* @param property The property
*/
function getValueOf(store: RdfStore, resource: string, property: string): Term {
return store.any(
$rdf.sym(resource),
$rdf.sym(property),
undefined,
undefined
);
}
/**
* Export the view
*/
export const VIEW_FOAF_PERSON: FoaFPersonRendering = new FoaFPersonRendering();
{
"compilerOptions": {
"outDir": "./lib/",
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es6",
"lib": [ "es6", "dom" ],
"jsx": "react"
},
"include": [
"./src/**/*"
],
}
\ No newline at end of file
const path = require("path");
const isProd = process.env.NODE_ENV === "production";
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = [
{
entry: "./src/foaf_person.ts",
mode: isProd ? "production" : "development",
output: {
path: path.join(__dirname, "build/"),
publicPath: path.join(__dirname, "build/"),
filename: "foaf_person.js"
},
devtool: "source-map",
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"]
},
module: {
rules: [
{ test: /\.tsx?$/, loader: "ts-loader" },
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
]
},
plugins: [
new CopyWebpackPlugin(
[{ from: "src/foaf.vd.json", to: "foaf.vd.json" }],
{}
)
],
devServer: {
contentBase: path.join(__dirname, "build"),
compress: true,
historyApiFallback: {
index: "index.html"
}
}
}
];
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment