Commit 32bfe0a4 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Factorizing code

parent d233f15a9c27
......@@ -21,7 +21,7 @@
import { RawContent, TabData, fetchSource } from "./api";
/// <reference path="./rdflib-interface.d.ts"/>
import { RDF, RdfStore } from "rdflib";
import { RDF, RdfStore, Term } from "rdflib";
let _rdf = require("rdflib");
export const $rdf: RDF = _rdf;
......@@ -53,6 +53,25 @@ export function loadRdfStore(tabData: TabData): Promise<any> {
});
}
/**
* 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
*/
export function getValueOf(
store: RdfStore,
resource: string,
property: string
): Term {
return store.any(
$rdf.sym(resource),
$rdf.sym(property),
undefined,
undefined
);
}
/**
* Determines whether the RDF store with the specified primary topic matches a trait:
* Has a primary topic
......
......@@ -27,7 +27,7 @@ import {
/// <reference path="../../common/rdflib-interface.d.ts"/>
import { RdfStore } from "rdflib";
import * as React from "react";
import { hasTraitDbPediaPerson, $rdf } from "../../common/rdf";
import { hasTraitDbPediaPerson, getValueOf, $rdf } from "../../common/rdf";
export class DBPediaPersonRendering implements ViewImplementation {
constructor() {
......@@ -53,12 +53,7 @@ export class DBPediaPersonRendering implements ViewImplementation {
root: string,
target: string
): React.ReactNode {
let name = store.any(
$rdf.sym(root),
$rdf.sym("http://xmlns.com/foaf/0.1/name"),
undefined,
undefined
).value;
let name = getValueOf(store, root, "http://xmlns.com/foaf/0.1/name").value;
return (
<div
style={{
......
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