-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c7d443
commit 5c07e63
Showing
42 changed files
with
1,626 additions
and
1,327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
# WF 2024-01-10 | ||
package=skg | ||
isort tests/*.py | ||
black tests/*.py | ||
isort $package/*.py | ||
black $package/*.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,117 @@ | ||
''' | ||
""" | ||
Created on 2022-12-21 | ||
@author: wf | ||
''' | ||
""" | ||
import datetime | ||
|
||
|
||
class Citeproc: | ||
""" | ||
see https://en.wikipedia.org/wiki/CiteProc | ||
""" | ||
|
||
@classmethod | ||
def asScite(cls,meta_data:dict,retrieved_from:str)->str: | ||
def asScite(cls, meta_data: dict, retrieved_from: str) -> str: | ||
""" | ||
convert the given meta data to #Scite format | ||
see https://github.com/SemanticMediaWiki/SemanticCite/blob/master/src/FilteredMetadata/BibliographicFilteredRecord.php | ||
Args: | ||
meta_data(dict): the citeproc compatible metadata dict to convert | ||
retrieved_from(str): the url the metadata was retrieved from | ||
Returns: | ||
str: Semantic Mediawiki markup | ||
""" | ||
|
||
def unlist(value): | ||
if type(value)!=list: | ||
if type(value) != list: | ||
return value | ||
text="" | ||
delim="" | ||
text = "" | ||
delim = "" | ||
for item in value: | ||
text+=f"{delim}{item}" | ||
delim=";" | ||
if len(value)>1: | ||
text+="|+sep=;" | ||
text += f"{delim}{item}" | ||
delim = ";" | ||
if len(value) > 1: | ||
text += "|+sep=;" | ||
return text | ||
|
||
def firstValue(value): | ||
if type(value)!=list: | ||
if type(value) != list: | ||
return value | ||
else: | ||
return value[0] | ||
def get_author(value)->str: | ||
|
||
def get_author(value) -> str: | ||
""" | ||
get the author markup | ||
Args: | ||
value(list): the list to disassemble | ||
Returns: | ||
str: Mediawiki markup | ||
""" | ||
author="" | ||
delim="" | ||
author = "" | ||
delim = "" | ||
for arec in value: | ||
if "given" in arec and "family" in arec: | ||
author+= f"""{delim}{arec["given"]} {arec["family"]}""" | ||
delim=";" | ||
author += f"""{delim}{arec["given"]} {arec["family"]}""" | ||
delim = ";" | ||
elif "family" in arec: | ||
author+= f"""{delim}{arec["family"]}""" | ||
delim=";" | ||
author += f"""{delim}{arec["family"]}""" | ||
delim = ";" | ||
else: | ||
# incomplete author record ignored | ||
pass | ||
return author | ||
timestamp=datetime.datetime.utcnow().strftime('%Y-%m-%d') | ||
ref_type="journal-article" | ||
title=meta_data["title"] | ||
|
||
timestamp = datetime.datetime.utcnow().strftime("%Y-%m-%d") | ||
ref_type = "journal-article" | ||
title = meta_data["title"] | ||
if type(title) is list: | ||
title=title[0] | ||
title_2=title.lower()[:2] | ||
author_lower="" | ||
title = title[0] | ||
title_2 = title.lower()[:2] | ||
author_lower = "" | ||
if "author" in meta_data: | ||
first_author=firstValue(meta_data["author"]) | ||
first_author = firstValue(meta_data["author"]) | ||
if "family" in first_author: | ||
family=firstValue(first_author["family"]) | ||
author_lower=family.lower() | ||
family = firstValue(first_author["family"]) | ||
author_lower = family.lower() | ||
else: | ||
# debug break point | ||
pass | ||
year="" | ||
year = "" | ||
if "published-print" in meta_data: | ||
year=meta_data["published-print"]["date-parts"][0][0] | ||
year = meta_data["published-print"]["date-parts"][0][0] | ||
if not year and "issued" in meta_data: | ||
year=meta_data["issued"]["date-parts"][0][0] | ||
reference=f"{author_lower}{year}{title_2}" | ||
markup="" | ||
for skey,mkey,func in [ | ||
("title","title",unlist), | ||
("subtitle","subtitle",unlist), | ||
("authors","author",get_author), | ||
("journal","container-title",unlist), | ||
("publisher","publisher",str), | ||
("issn","ISSN",unlist), | ||
("subject","subject",unlist), | ||
("volume","volume",str), | ||
("pages","page",str), | ||
("doi","DOI",str) | ||
year = meta_data["issued"]["date-parts"][0][0] | ||
reference = f"{author_lower}{year}{title_2}" | ||
markup = "" | ||
for skey, mkey, func in [ | ||
("title", "title", unlist), | ||
("subtitle", "subtitle", unlist), | ||
("authors", "author", get_author), | ||
("journal", "container-title", unlist), | ||
("publisher", "publisher", str), | ||
("issn", "ISSN", unlist), | ||
("subject", "subject", unlist), | ||
("volume", "volume", str), | ||
("pages", "page", str), | ||
("doi", "DOI", str), | ||
]: | ||
if mkey in meta_data: | ||
value=meta_data[mkey] | ||
value = meta_data[mkey] | ||
if value: | ||
value=func(value) | ||
markup+=f"\n|{skey}={value}" | ||
markup=f"""{{{{#scite: | ||
value = func(value) | ||
markup += f"\n|{skey}={value}" | ||
markup = f"""{{{{#scite: | ||
|reference={reference} | ||
|type={ref_type}{markup} | ||
|year={year} | ||
|retrieved-from={retrieved_from} | ||
|retrieved-on={timestamp} | ||
}}}}""" | ||
full_markup=f"{title}\n[[CiteRef::{reference}]]\n{markup}" | ||
full_markup = f"{title}\n[[CiteRef::{reference}]]\n{markup}" | ||
return full_markup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,63 @@ | ||
''' | ||
""" | ||
Created on 17.11.2022 | ||
@author: wf | ||
''' | ||
import skg | ||
""" | ||
import habanero | ||
import habanero.cn as cn | ||
|
||
import skg | ||
from skg.citeproc import Citeproc | ||
|
||
|
||
class Crossref: | ||
""" | ||
Crossref access | ||
""" | ||
def __init__(self,mailto=None,ua_string=None): | ||
|
||
def __init__(self, mailto=None, ua_string=None): | ||
""" | ||
constructor | ||
""" | ||
if mailto is None: | ||
mailto="[email protected]" | ||
mailto = "[email protected]" | ||
if ua_string is None: | ||
ua_string=f"pysotsog/{skg.__version__} (https://pypi.org/project/pysotsog/; mailto:{mailto})" | ||
#self.cr = habanero.Crossref(mailto=mailto,ua_string=ua_string) | ||
self.cr = habanero.Crossref(ua_string="") | ||
def doiMetaData(self, dois:list): | ||
""" | ||
ua_string = f"pysotsog/{skg.__version__} (https://pypi.org/project/pysotsog/; mailto:{mailto})" | ||
# self.cr = habanero.Crossref(mailto=mailto,ua_string=ua_string) | ||
self.cr = habanero.Crossref(ua_string="") | ||
|
||
def doiMetaData(self, dois: list): | ||
""" | ||
get the meta data for the given dois | ||
Args: | ||
doi(list): a list of dois | ||
""" | ||
metadata = None | ||
response = self.cr.works(ids=dois) | ||
if 'status' in response and 'message' in response and response['status'] == 'ok': | ||
metadata = response['message'] | ||
if ( | ||
"status" in response | ||
and "message" in response | ||
and response["status"] == "ok" | ||
): | ||
metadata = response["message"] | ||
return metadata | ||
def doiBibEntry(self,dois:list): | ||
|
||
def doiBibEntry(self, dois: list): | ||
""" | ||
get bib entries for the given dois | ||
""" | ||
bibentry=cn.content_negotiation(ids = dois, format = "bibentry") | ||
bibentry = cn.content_negotiation(ids=dois, format="bibentry") | ||
return bibentry | ||
def asScite(self,meta_data:dict)->str: | ||
|
||
def asScite(self, meta_data: dict) -> str: | ||
""" | ||
convert the given meta data to #Scite format | ||
see https://github.com/SemanticMediaWiki/SemanticCite/blob/master/src/FilteredMetadata/BibliographicFilteredRecord.php | ||
Returns: | ||
str: Semantic Mediawiki markup | ||
""" | ||
markup=Citeproc.asScite(meta_data,retrieved_from=self.cr.base_url) | ||
markup = Citeproc.asScite(meta_data, retrieved_from=self.cr.base_url) | ||
return markup | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Created on 2024-02-26 | ||
@author: wf | ||
""" | ||
from argparse import Namespace | ||
|
||
class Dblp2Wikidata: | ||
""" | ||
utility to transfering Dblp person entries to Wikidata | ||
""" | ||
|
||
def __init__(self,debug:bool=False): | ||
self.debug=debug | ||
pass | ||
|
||
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) | ||
if self.debug: | ||
print(f"trying to transfer DBLP person entry for {search_term}") |
Oops, something went wrong.