Skip to content

Commit

Permalink
SAND Entity Editor UI, when users link new cell, it will automaticall…
Browse files Browse the repository at this point in the history
…y do an initial search using the cell as the query to save users time from re-entering the same information.
  • Loading branch information
Binh Vu committed Apr 13, 2024
1 parent 145a713 commit 3f4d049
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Added

- SAND Entity Editor UI, when users link new cell, it will automatically do an initial search using the cell as the query to save users time from re-entering the same information.

## [4.1.0] - 2024-04-13

### Added
Expand Down
15 changes: 15 additions & 0 deletions extensions/sand_grams/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.poetry]
name = "sand-grams"
version = "1.0.0"
description = "SAND & GRAMS Integration"
authors = ["Binh Vu <[email protected]>"]
license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file.
25 changes: 25 additions & 0 deletions extensions/sand_grams/sand_grams/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import annotations

from dependency_injector.wiring import Provide, inject

from sand.config import AppConfig
from sand.extension_interface.assistant import IAssistant
from sand.helpers.namespace import NamespaceService
from sand.models.table import Link, Table, TableRow


class GRAMSAssistant(IAssistant):

@inject
def __init__(
self,
appcfg: AppConfig = Provide["appcfg"],
namespace: NamespaceService = Provide["namespace"],
):
self.appcfg = appcfg
self.namespace = namespace

# def predict_entities(
# self, table: Table, rows: list[TableRow], row: int, col: int
# ) -> list[Link]:
# text = str(rows[row].row[col])
24 changes: 12 additions & 12 deletions sand/extension_interface/assistant.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, List, Optional, Tuple
from typing import Optional

from sand.models.table import Table, TableRow
from sm.outputs.semantic_model import SemanticModel

if TYPE_CHECKING:
from sand.app import App
from sand.models.table import Link, Table, TableRow


class IAssistant(ABC):
def __init__(self, app: App):
self.app = app

@abstractmethod
class IAssistant:
def predict(
self, table: Table, rows: List[TableRow]
) -> Tuple[Optional[SemanticModel], Optional[List[TableRow]]]:
self, table: Table, rows: list[TableRow]
) -> tuple[Optional[SemanticModel], Optional[list[TableRow]]]:
"""Predict semantic model and link entities"""
pass
raise NotImplementedError()

def predict_entities(
self, table: Table, rows: list[TableRow], row: int, col: int
) -> list[Link]:
"""Predict entities for a cell"""
raise NotImplementedError()
8 changes: 5 additions & 3 deletions sand/extensions/assistants/mtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
import serde.prelude as serde
import sm.outputs.semantic_model as O
from rdflib import RDFS
from sm.namespaces.wikidata import WikidataNamespace

from sand.controllers.assistant import IAssistant
from sand.models.base import init_db
from sand.models.table import CandidateEntity, Link, Table, TableRow
from sm.namespaces.wikidata import WikidataNamespace


class MTabAssistant(IAssistant):
def __init__(self, app):
super().__init__(app)
def __init__(
self,
):
self.cache_dir = Path(f"/tmp/mtab")
self.cache_dir.mkdir(exist_ok=True)
self.wdns = WikidataNamespace.create()
Expand Down
2 changes: 1 addition & 1 deletion www/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sand",
"version": "2.2.4",
"version": "2.3.0",
"private": true,
"dependencies": {
"@ant-design/colors": "^6.0.0",
Expand Down
13 changes: 12 additions & 1 deletion www/src/pages/table/OntSearchComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WithStyles, withStyles } from "@material-ui/styles";
import { Select, Spin } from "antd";
import { observer } from "mobx-react";
import { useState } from "react";
import { useEffect, useState } from "react";
import { useStores } from "../../models";
import SearchOptionsComponent from "./SearchOptionsComponent";
import { debounce } from "lodash";
Expand All @@ -17,6 +17,7 @@ const styles = {
};

type SearchProps = {
defaultSearchQuery?: string;
value?: string | string[];
onDeselect?: (value: string) => void;
onSelect?: (value: string) => void;
Expand Down Expand Up @@ -53,6 +54,7 @@ function useSearchComponent(
if (query === "") {
return;
}

const loaderOption: SearchOptions = {
id: "",
label: <Spin style={{ width: "100%", marginTop: 3 }} size="large" />,
Expand Down Expand Up @@ -85,6 +87,15 @@ function useSearchComponent(
});
};

// if default search query is provided, we should do an initial search to get the results so users
// can click immediately -- this is a work around to antd lack of setting a default query.
// however, the dropdown isn't triggered by default -- we can improve it so it save users one click
useEffect(() => {
if (props.defaultSearchQuery !== undefined) {
onSearch(props.defaultSearchQuery);
}
}, [props.defaultSearchQuery || ""]);

return (
<Select
allowClear={true}
Expand Down
1 change: 1 addition & 0 deletions www/src/pages/table/table/CandidateEntityListComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export const CandidateEntityListComponent = withStyles(styles)(
Modal.destroyAll();
});
}}
defaultSearchQuery={record.row[index].toString()}
/>
);

Expand Down

0 comments on commit 3f4d049

Please sign in to comment.