Skip to content

Commit

Permalink
refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Mar 8, 2024
1 parent 5c07e63 commit f4d5e53
Show file tree
Hide file tree
Showing 8 changed files with 408 additions and 114 deletions.
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ readme = "README.md"
license= "Apache-2.0"
dependencies = [
"nicegui",
"ngwidgets>=0.6.0",
"ngwidgets>=0.14.0",
# https://pypi.org/project/pylodstorage/
'pyLodStorage>=0.4.7',
'pyLodStorage>=0.9.0',
# https://pypi.org/project/habanero/
'habanero~=1.2.2',
# https://pypi.org/project/search-engine-parser/
Expand All @@ -34,7 +34,10 @@ dependencies = [
# https://arthurdejong.org/python-stdnum/
'python-stdnum>=1.18',
# https://pypi.org/project/pyOnlineSpreadsheetEditing/
'pyOnlineSpreadsheetEditing>=0.2.1'
#'pyOnlineSpreadsheetEditing>=0.2.1',
'py_ez_wikidata>=0.1.5',
# https://github.com/MrTango/rispy
'rispy>=0.9.0'
]

requires-python = ">=3.8"
Expand Down
34 changes: 34 additions & 0 deletions skg/resources/queries/stt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Sample Queries for Software Technik Trends
#
# WF 2024-03-08
'STT-Papers':
sparql: |
# Papers published in a certain venue
# e.g. Softwaretechnik-Trends
# WF 2024-03-08
PREFIX dblp: <https://dblp.org/rdf/schema#>
SELECT
?paper
?title
(GROUP_CONCAT(DISTINCT ?author; SEPARATOR="; ") AS ?authors)
?year
?archivedWebpage
?listedOnTocPage
?volume
?issue
(COUNT(DISTINCT ?author) AS ?author_count)
WHERE {
?paper dblp:publishedIn "Softwaretechnik-Trends".
OPTIONAL{?paper dblp:title ?title .}
OPTIONAL{?paper dblp:authoredBy ?author .}
OPTIONAL{?paper dblp:yearOfPublication ?year .}
OPTIONAL{?paper dblp:archivedWebpage ?archivedWebpage .}
OPTIONAL{?paper dblp:listedOnTocPage ?listedOnTocPage .}
OPTIONAL{?paper dblp:publishedInJournalVolume ?volume .}
OPTIONAL{?paper dblp:publishedInJournalVolumeIssue ?issue .}
# Other fields from the n-triples not explicitly queried due to their nature or presumed relevance.
# This includes fields like hasIdentifier, hasSignature, etc., which are typically used for internal management or more detailed data tracking.
}
GROUP BY ?paper ?title ?year ?archivedWebpage ?listedOnTocPage ?volume ?issue
ORDER BY ?year
96 changes: 96 additions & 0 deletions skg/ris.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""
Created on 2024-03-08
@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

@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
year: Optional[str] = None
doi: Optional[str] = None
keywords: List[str] = field(default_factory=list)
first_authors: List[str] = field(default_factory=list)
publisher: Optional[str] = None
language: Optional[str] = None
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"
return qid

@classmethod
def get_property_mappings(cls):
"""
get the wikidata property mappings
"""
mappings=[
PropertyMapping(
column="instanceof",
propertyName="instanceof",
propertyId="P31",
propertyType=WdDatatype.itemid,
value="Q13442814", # scholarly article
),
PropertyMapping(
column="primary_title",
propertyName="title",
propertyId="P1476",
propertyType=WdDatatype.text,
),
PropertyMapping(
column="doi",
#propertyName="DOI",
#propertyId="P356",
propertyName="described at URL",
propertyId="P973",
#propertyType=WdDatatype.extid,
propertyType=WdDatatype.url
),
PropertyMapping(
column="lang_qid",
propertyName="language of work or name",
propertyId="P407",
propertyType=WdDatatype.itemid,
),
PropertyMapping(
column="year",
propertyName="publication date",
propertyId="P577",
propertyType=WdDatatype.year,
),
]
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:
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
else:
if by_field in entry:
value=field[entry]
ris_dict[value]=ris_entry

return ris_dict

54 changes: 37 additions & 17 deletions skg/skgbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from urllib import parse

from ngwidgets.input_webserver import InputWebserver
from ngwidgets.input_webserver import InputWebserver, InputWebSolution
from ngwidgets.webserver import WebserverConfig
from ngwidgets.widgets import Lang, Link
from nicegui import Client, ui
Expand All @@ -24,35 +24,55 @@ class SkgBrowser(InputWebserver):

@classmethod
def get_config(cls) -> WebserverConfig:
copy_right = "(c)2022 Wolfgang Fahl"
if not hasattr(cls, "config"):
cls.config = WebserverConfig(
copy_right=copy_right, version=Version(), default_port=8765
)
return cls.config
copy_right = "(c)2022-2024 Wolfgang Fahl"
config = WebserverConfig(
copy_right=copy_right,
version=Version(),
default_port=8765,
short_name="sotsog"
)
server_config = WebserverConfig.get(config)
server_config.solution_class = SkgSolution
return server_config

def __init__(self):
"""Constructs all the necessary attributes for the WebServer object."""
config = SkgBrowser.get_config()
self.sotsog = config.sotsog
self.options = config.options
InputWebserver.__init__(self, config=config)
self.language = "en"
self.wikiId = "or"
self.markup_name = None


def configure_run(self):
self.markup_names = ["-", "bibtex", "scite", "smw"]
self.markup_name = self.markup_names[1]
# 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.scholars(client)
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
Calls the constructor of the base solution
Args:
webserver (SkgBrowser): The webserver instance associated with this context.
client (Client): The client instance this context is associated with.
"""
super().__init__(webserver, client) # Call to the superclass constructor
self.language = "en"
self.wikiId = "or"
self.markup_names = ["-", "bibtex", "scite", "smw"]
self.markup_name = self.markup_names[1]


def configure_menu(self):
"""
Expand Down
86 changes: 2 additions & 84 deletions skg/sotsog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
@author: wf
"""
import sys
import webbrowser
from argparse import ArgumentParser

from ngwidgets.ngwidgets_cmd import WebserverCmd

from skg.crossref import Crossref
from skg.doi import DOI
Expand All @@ -20,9 +16,8 @@
from skg.smw import SemWiki
from skg.wdsearch import WikidataSearch
from skg.wikidata import Wikidata
from skg.dblp2wikidata import Dblp2Wikidata

class SotSog(WebserverCmd):
class SotSog():
"""
Standing on the shoulders of giants
"""
Expand All @@ -32,9 +27,6 @@ def __init__(self):
constructor
"""
self.config = SkgBrowser.get_config()
self.config.sotsog = self
WebserverCmd.__init__(self, self.config, SkgBrowser, DEBUG)
Node.debug = self.debug
self.wikipedia_url = (
"https://en.wikipedia.org/wiki/Standing_on_the_shoulders_of_giants"
Expand Down Expand Up @@ -176,78 +168,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

def getArgParser(self, description: str, version_msg) -> ArgumentParser:
"""
override the default argparser call
"""
parser = super().getArgParser(description, version_msg)
parser.add_argument("search", action="store", nargs="*", help="search terms")
parser.add_argument(
"--bibtex", help="output bibtex format", action="store_true"
)
parser.add_argument("-la", "--lang", help="language code to use", default="en")
parser.add_argument(
"-li",
"--limit",
help="limit the number of search results",
type=int,
default=9,
)
parser.add_argument(
"-nb", "--nobrowser", help="do not open browser", action="store_true"
)
parser.add_argument("--scite", help="output #scite format", action="store_true")
parser.add_argument(
"--smw", help="output Semantic MediaWiki (SMW) format", action="store_true"
)
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")

return parser

def handle_args(self) -> bool:
"""
handle the command line args
"""
markup_names = []
args = self.args
if args.bibtex:
markup_names.append("bibtex")
if args.scite:
markup_names.append("scite")
if args.smw:
markup_names.append("smw")
self.config.options = SearchOptions(
limit=args.limit,
lang=args.lang,
markup_names=markup_names,
open_browser=not args.nobrowser,
)
handled = super().handle_args()
if not handled:
if args.dblp2wikidata:
d2w=Dblp2Wikidata()
d2w.transfer(args)
self.search(args.search, self.config.options)
handled = True
return handled


def main(argv: list = None):
"""
main call
"""
cmd = SotSog()
exit_code = cmd.cmd_main(argv)
return exit_code


DEBUG = 0
if __name__ == "__main__":
if DEBUG:
sys.argv.append("-d")
sys.exit(main())
return search_result
Loading

0 comments on commit f4d5e53

Please sign in to comment.