Skip to content

Commit

Permalink
improves
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Jun 19, 2024
1 parent 09f2d5f commit 86a2937
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 151 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ readme = "README.md"
license= "Apache-2.0"
dependencies = [
"nicegui",
"ngwidgets>=0.14.0",
"ngwidgets>=0.15.0",
# https://pypi.org/project/pylodstorage/
'pyLodStorage>=0.9.2',
# https://pypi.org/project/habanero/
Expand Down
17 changes: 9 additions & 8 deletions skg/dblp2wikidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
"""
from argparse import Namespace


class Dblp2Wikidata:
"""
utility to transfering Dblp person entries to Wikidata
utility for transfering Dblp person entries to Wikidata
"""

def __init__(self,debug:bool=False):
self.debug=debug
def __init__(self, debug: bool = False):
self.debug = debug
pass
def transfer(self, args:Namespace):

def transfer(self, args: Namespace):
"""
Main method to handle the transfer of DBLP entries to Wikidata.
Args:
args(Namespace): Command line arguments.
"""
search_term = getattr(args, 'dblp2wikidata', None)
search_term = getattr(args, "dblp2wikidata", None)
if self.debug:
print(f"trying to transfer DBLP person entry for {search_term}")
print(f"trying to synchronize DBLP person entry for {search_term}")
64 changes: 33 additions & 31 deletions skg/ris.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
@author: wf
"""
from lodstorage.yamlable import lod_storable
from dataclasses import field
from typing import List, Optional
from ez_wikidata.wdproperty import PropertyMapping, WdDatatype

import rispy
from ez_wikidata.wdproperty import PropertyMapping, WdDatatype
from lodstorage.yamlable import lod_storable


@lod_storable
class RIS_Entry:
"""
Research Information Systems format
https://en.wikipedia.org/wiki/RIS_(file_format)
"""

type_of_reference: Optional[str] = None
abstract: Optional[str] = None
type_of_work: Optional[str] = None
Expand All @@ -27,26 +30,26 @@ class RIS_Entry:
primary_title: Optional[str] = None
urls: List[str] = field(default_factory=list)
secondary_title: Optional[str] = None

@property
def lang_qid(self)->str:
qid="Q1860" # English
if self.language=="de":
qid="Q188"
def lang_qid(self) -> str:
qid = "Q1860" # English
if self.language == "de":
qid = "Q188"
return qid

@classmethod
def get_property_mappings(cls):
"""
get the wikidata property mappings
"""
mappings=[
mappings = [
PropertyMapping(
column="instanceof",
propertyName="instanceof",
propertyId="P31",
propertyType=WdDatatype.itemid,
value="Q13442814", # scholarly article
column="instanceof",
propertyName="instanceof",
propertyId="P31",
propertyType=WdDatatype.itemid,
value="Q13442814", # scholarly article
),
PropertyMapping(
column="primary_title",
Expand All @@ -56,12 +59,12 @@ def get_property_mappings(cls):
),
PropertyMapping(
column="doi",
#propertyName="DOI",
#propertyId="P356",
# propertyName="DOI",
# propertyId="P356",
propertyName="described at URL",
propertyId="P973",
#propertyType=WdDatatype.extid,
propertyType=WdDatatype.url
propertyId="P973",
# propertyType=WdDatatype.extid,
propertyType=WdDatatype.url,
),
PropertyMapping(
column="lang_qid",
Expand All @@ -77,20 +80,19 @@ def get_property_mappings(cls):
),
]
return mappings

@classmethod
def get_dict_from_file(cls,ris_file_path,by_field:str="index"):
ris_dict={}
with open(ris_file_path, 'r') as bibliography_file:
def get_dict_from_file(cls, ris_file_path, by_field: str = "index"):
ris_dict = {}
with open(ris_file_path, "r") as bibliography_file:
entries = rispy.load(bibliography_file)
for i,entry in enumerate(entries,start=1):
ris_entry=RIS_Entry.from_dict(entry)
if by_field=="index":
value=i
for i, entry in enumerate(entries, start=1):
ris_entry = RIS_Entry.from_dict(entry)
if by_field == "index":
value = i
else:
if by_field in entry:
value=field[entry]
ris_dict[value]=ris_entry

return ris_dict
value = field[entry]
ris_dict[value] = ris_entry

return ris_dict
8 changes: 4 additions & 4 deletions skg/scholargrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"""
from typing import Callable

from ez_wikidata.wbquery import WikibaseQuery
from lodstorage.sparql import SPARQL
from spreadsheet.wbquery import WikibaseQuery
from wd.wdgrid import GridSync, WikidataGrid

from skg.smw import SemWiki
Expand Down Expand Up @@ -159,7 +159,7 @@ class SmwGrid(GridSync):

def __init__(
self,
app,
solution,
entityName: str,
entityPluralName: str,
pk: str,
Expand All @@ -173,7 +173,7 @@ def __init__(
constructor
Args:
app(App): the app that i am part of
solution: the solutio that i am part of
entityName(str): the name of the entity type of items to be shown in the grid
entityPluralName(str): the plural name of the entities to be shown
pk(str): the name of the primary key
Expand All @@ -183,7 +183,7 @@ def __init__(
sparql(SPARQL): the SPARQL endpoint to use
debug(bool): if True show debugging information
"""
self.app = app
self.solution = solution
self.wikiUsers = wikiUsers
self.wikiId = wikiId
wikiUser = self.wikiUsers[wikiId]
Expand Down
22 changes: 10 additions & 12 deletions skg/skgbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class SkgBrowser(InputWebserver):
def get_config(cls) -> WebserverConfig:
copy_right = "(c)2022-2024 Wolfgang Fahl"
config = WebserverConfig(
copy_right=copy_right,
version=Version(),
copy_right=copy_right,
version=Version(),
default_port=8765,
short_name="sotsog"
short_name="sotsog",
)
server_config = WebserverConfig.get(config)
server_config.solution_class = SkgSolution
Expand All @@ -39,25 +39,24 @@ def __init__(self):
"""Constructs all the necessary attributes for the WebServer object."""
config = SkgBrowser.get_config()
InputWebserver.__init__(self, config=config)


@ui.page("/scholars")
async def scholars(client: Client):
return await self.page(client, SkgSolution.scholars)

def configure_run(self):
# wiki users
self.wikiUsers = WikiUser.getWikiUsers()
self.wikiId = self.args.wikiId
wikidata = Wikidata()
self.sparql = wikidata.sparql

@ui.page("/scholars")
async def scholars(client: Client):
return await self.page(
client, SkgSolution.scholars
)


def SkgSolution(InputWebSolution):
"""
the scholarly knowledge graph solution
"""

def __init__(self, webserver: SkgBrowser, client: Client):
"""
Initialize the solution
Expand All @@ -72,7 +71,6 @@ def __init__(self, webserver: SkgBrowser, client: Client):
self.wikiId = "or"
self.markup_names = ["-", "bibtex", "scite", "smw"]
self.markup_name = self.markup_names[1]


def configure_menu(self):
"""
Expand Down
5 changes: 3 additions & 2 deletions skg/sotsog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from skg.wdsearch import WikidataSearch
from skg.wikidata import Wikidata

class SotSog():

class SotSog:
"""
Standing on the shoulders of giants
"""
Expand Down Expand Up @@ -168,4 +169,4 @@ def search(self, search_list, options: SearchOptions) -> SearchResult:
else:
items = self.wd_search(wd, search_term, options)
search_result.items = items
return search_result
return search_result
34 changes: 23 additions & 11 deletions skg/sotsog_cmd.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
'''
"""
Created on 2024-02-26
@author: wf
'''
"""
import sys
from argparse import ArgumentParser
from skg.sotsog import SotSog, SearchOptions

from ngwidgets.ngwidgets_cmd import WebserverCmd

from skg.dblp2wikidata import Dblp2Wikidata
from skg.skgbrowser import SkgBrowser
from skg.sotsog import SearchOptions, SotSog

from ngwidgets.ngwidgets_cmd import WebserverCmd

class SotSogCmd(WebserverCmd):
"""
command line handling for Standing on the Shoulders of Giants
command line handling for Standing on the Shoulders of Giants
"""

def __init__(self):
"""
constructor
"""
self.config = SkgBrowser.get_config()
WebserverCmd.__init__(self, self.config, SkgBrowser, DEBUG)

Expand Down Expand Up @@ -47,8 +52,13 @@ def getArgParser(self, description: str, version_msg) -> ArgumentParser:
parser.add_argument(
"--wikiId", help="the id of the SMW wiki to connect with", default="ceur-ws"
)
parser.add_argument("-dw","--dblp2wikidata", action="store_true", help="Transfer DBLP entries to Wikidata")

parser.add_argument(
"-dw",
"--dblp2wikidata",
action="store_true",
help="Synchronize DBLP entries with Wikidata",
)

return parser

def handle_args(self) -> bool:
Expand All @@ -73,12 +83,14 @@ def handle_args(self) -> bool:
handled = super().handle_args()
if not handled:
if args.dblp2wikidata:
d2w=Dblp2Wikidata()
d2w.transfer(args)
d2w = Dblp2Wikidata()
handled=d2w.transfer(args)
if not handled:
self.search(args.search, self.sotsog.options)
handled = True
return handled


def main(argv: list = None):
"""
main call
Expand All @@ -92,4 +104,4 @@ def main(argv: list = None):
if __name__ == "__main__":
if DEBUG:
sys.argv.append("-d")
sys.exit(main())
sys.exit(main())
2 changes: 1 addition & 1 deletion tests/testScholarGrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
@author: wf
"""
from ez_wikidata.wbquery import WikibaseQuery
from ngwidgets.basetest import Basetest
from spreadsheet.wbquery import WikibaseQuery
from wikibot3rd.wikiuser import WikiUser

from skg.scholargrid import ScholarGrid, ScholarQuery
Expand Down
14 changes: 8 additions & 6 deletions tests/test_dblp2wikidata.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'''
"""
Created on 2024-02-26
@author: wf
'''
"""
from argparse import Namespace

from ngwidgets.basetest import Basetest

from skg.dblp2wikidata import Dblp2Wikidata
from argparse import Namespace


class TestDblp2Wikidata(Basetest):
"""
Expand All @@ -15,13 +18,12 @@ class TestDblp2Wikidata(Basetest):
def setUp(self, debug=True, profile=True):
Basetest.setUp(self, debug=debug, profile=profile)
self.d2w = Dblp2Wikidata(debug=debug)

def test_transfer(self):
"""
Test the transfer method for a known DBLP entry
"""
test_search_terms=["82/6542","Donald C. Gause"]
test_search_terms = ["82/6542", "Donald C. Gause"]
for test_search_term in test_search_terms:
test_args = Namespace(dblp2wikidata=test_search_term)
self.d2w.transfer(test_args)

Loading

0 comments on commit 86a2937

Please sign in to comment.