Skip to content

Commit

Permalink
Showing documents with triplets marked up
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperFyhn committed Dec 6, 2024
1 parent 4a86104 commit a07c2cc
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ def span_to_json(span: Union[Span, Doc]) -> Dict[str, Any]:
span = span[:]
return {
"text": span.text,
"start_char": span.start_char,
"start": span.start,
"end_char": span.end_char,
"end": span.end,
}

Expand Down
138 changes: 138 additions & 0 deletions visualizer/package-lock.json

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

2 changes: 2 additions & 0 deletions visualizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
"@types/jest": "^27.5.2",
"@types/node": "^16.18.96",
"@types/react-dom": "^18.2.24",
"draft-js": "^0.11.7",
"multi-range-slider-react": "^2.0.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-graph-vis": "^1.0.7",
"react-highlight-within-textarea": "^3.2.2",
"react-router-dom": "^6.22.3",
"react-scripts": "5.0.1",
"react-vis-graph-wrapper": "^0.1.3",
Expand Down
38 changes: 30 additions & 8 deletions visualizer/src/docs/DocService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,25 @@ export abstract class DocService {
}
}

export interface TripletField {
text: string;
start_char: number;
start: number;
end_char: number;
end: number;
}

export interface Triplet {
subject: TripletField;
predicate: TripletField;
object: TripletField;
}

export interface Doc {
id: string;
text: string;
timestamp: string;
semantic_triplets: Triplet[];
}

export class SampleDocService extends DocService {
Expand All @@ -25,16 +40,19 @@ export class SampleDocService extends DocService {
id: "1",
text: "sample text 1",
timestamp: "",
semantic_triplets: [],
},
{
id: "2",
text: "sample text 1",
timestamp: "",
semantic_triplets: [],
},
{
id: "3",
text: "sample text 1",
timestamp: "",
semantic_triplets: [],
},
].map((d) => [d.id, d]),
);
Expand All @@ -58,14 +76,18 @@ export class FileDocService extends DocService {
constructor(docData: Doc[]) {
super();
this.docData = new Map(
docData.map((d) => [
d.id,
{
id: d.id,
text: d.text,
timestamp: d.timestamp,
},
]),
docData
.filter((d) => d.semantic_triplets !== undefined)
.map((d) => [
d.id,
{
id: d.id,
text: d.text,
timestamp: d.timestamp,
semantic_triplets: d.semantic_triplets,
},
]),
);
console.log(this.docData.size);
}
}
4 changes: 2 additions & 2 deletions visualizer/src/graph/GraphViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useServiceContext } from "../service/ServiceContextProvider";
export interface GraphViewerProps {}

export const GraphViewer: React.FC = () => {
const { getGraphService, getDocService } = useServiceContext();
const { getGraphService } = useServiceContext();

const top50 =
getGraphService()
Expand Down Expand Up @@ -45,7 +45,7 @@ export const GraphViewer: React.FC = () => {
? getGraphService().getSubGraph(subgraphNodes)
: getGraphService().getGraph();
return filter(graphFilter, baseGraphData);
}, [graphFilter, subgraphNodes]);
}, [getGraphService, graphFilter, subgraphNodes]);

const graphDataMaps = useMemo(() => {
return {
Expand Down
Loading

0 comments on commit a07c2cc

Please sign in to comment.