Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find a way to shorten blank node ids #60

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/first.sparqlbook
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
{
"kind": 2,
"language": "sparql",
"value": "# [endpoint=http://test.lindas.admin.ch/query]\nPREFIX schema: <http://schema.org/>\n\nSELECT ?propertyShape ?p ?o WHERE {\n BIND (<https://politics.ld.admin.ch/vocabulary/party> as ?set)\n ?set <http://www.w3.org/ns/shacl#property> ?propertyShape . \n ?propertyShape ?p ?o .\n} ",
"value": "# [endpoint=http://test.lindas.admin.ch/query]\nPREFIX schema: <http://schema.org/>\n\nSELECT ?propertyShape ?p ?o WHERE {\n {\n SELECT ?propertyShape WHERE {\n ?set <http://www.w3.org/ns/shacl#property> ?propertyShape . \n FILTER(isBlank(?propertyShape))\n } LIMIT 30\n }\n ?propertyShape ?p ?o .\n} ",
"metadata": {}
}
]
5 changes: 3 additions & 2 deletions src/renderer/components/bnode-component/bnode-component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react';

import { Term } from '../../model/sparql-result-json.model';
import { shrinkBnode } from './shrink-bnode';

interface BNodeComponentProps {
term: Term;
Expand All @@ -16,7 +17,7 @@ export const BNodeComponent: React.FC<BNodeComponentProps> = ({ term }) => {
throw new Error('Term is not a blank node');
}

const value = term.value;
const value = shrinkBnode(term.value);


const bNode: BlankNode = {
Expand All @@ -32,7 +33,7 @@ export const BNodeComponent: React.FC<BNodeComponentProps> = ({ term }) => {

return (
<div style={{ display: 'flex', flexDirection: 'row' }}>
<span>[{blankNode?.value}]</span>
<span title="Blank Node">{blankNode?.value}</span>
</div>
);
};
Expand Down
12 changes: 12 additions & 0 deletions src/renderer/components/bnode-component/shrink-bnode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

let bNodeIdIndex = 0;
const bNodeMap = new Map<string, string>();

export function shrinkBnode(bNodeId: string): string {
if (bNodeMap.has(bNodeId)) {
return bNodeMap.get(bNodeId) ?? '';
}
const newBNodeId = `_:b${bNodeIdIndex++}`;
bNodeMap.set(bNodeId, newBNodeId);
return newBNodeId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const LiteralComponent: React.FC<LiteralComponentProps> = ({ term }) => {

return (
<div className="row">
<span className="value">{literal?.value}</span>
<span title="Literal" className="value">{literal?.value}</span>
<span className="meta">
{' '}
{literal?.languageTag ? '@' + literal.languageTag : ''}
Expand Down