-
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
ac2a1ca
commit 1818ffd
Showing
11 changed files
with
307 additions
and
302 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 |
---|---|---|
@@ -1,39 +1,43 @@ | ||
''' | ||
""" | ||
Created on 2022-11-21 | ||
@author: wf | ||
''' | ||
from tests.basetest import Basetest | ||
""" | ||
from ngwidgets.basetest import Basetest | ||
from skg.kg import SKG_Def | ||
|
||
|
||
class BaseSkgTest(Basetest): | ||
""" | ||
extend the Basetest | ||
""" | ||
|
||
def setUp(self, debug=False, profile=True): | ||
Basetest.setUp(self, debug=debug, profile=profile) | ||
self.skg_def=SKG_Def() | ||
|
||
def check_id_examples(self,id_examples,createFunc,checkItem,debug:bool=False): | ||
self.skg_def = SKG_Def() | ||
|
||
def check_id_examples( | ||
self, id_examples, createFunc, checkItem, debug: bool = False | ||
): | ||
""" | ||
check the given examples | ||
Args: | ||
id_examples(list): a list of dict with examples | ||
createFunct(func): a function to be used to create items | ||
checkItem(func): a function to be called for testing each item | ||
debug(bool): if True show debug information | ||
""" | ||
for id_example in id_examples: | ||
id_name=id_example["id_name"] | ||
id_value=id_example["id_value"] | ||
id_concept=id_example["concept"] | ||
id_name = id_example["id_name"] | ||
id_value = id_example["id_value"] | ||
id_concept = id_example["concept"] | ||
# use createFunc as a factory | ||
items=createFunc(id_concept,id_name,id_value) | ||
items = createFunc(id_concept, id_name, id_value) | ||
if debug: | ||
for item in items: | ||
print(item) | ||
self.assertEqual(1,len(items)) | ||
item=items[0] | ||
self.assertEqual(item.concept.name,id_concept.name) | ||
checkItem(item,id_name,id_value,debug) | ||
self.assertEqual(1, len(items)) | ||
item = items[0] | ||
self.assertEqual(item.concept.name, id_concept.name) | ||
checkItem(item, id_name, id_value, debug) |
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,43 +1,46 @@ | ||
''' | ||
""" | ||
Created on 2023-01-04 | ||
@author: wf | ||
''' | ||
from tests.basetest import Basetest | ||
""" | ||
from ngwidgets.basetest import Basetest | ||
from skg.scholargrid import ScholarGrid, ScholarQuery | ||
from wikibot3rd.wikiuser import WikiUser | ||
from spreadsheet.wbquery import WikibaseQuery | ||
from skg.wikidata import Wikidata | ||
|
||
|
||
class TestScholarGrid(Basetest): | ||
""" | ||
test Scholar Grid behavior | ||
""" | ||
|
||
def testScholarQuery(self): | ||
""" | ||
test the Wikibase Query for Scholars | ||
""" | ||
debug=True | ||
sq=ScholarQuery.get() | ||
debug = True | ||
sq = ScholarQuery.get() | ||
self.assertIsNotNone(sq) | ||
self.assertTrue(isinstance(sq,WikibaseQuery)) | ||
self.assertTrue(isinstance(sq, WikibaseQuery)) | ||
if debug: | ||
print(sq) | ||
|
||
def testGetScholars(self): | ||
""" | ||
test getting scholars | ||
""" | ||
wikiUsers=WikiUser.getWikiUsers() | ||
wikidata=Wikidata() | ||
sparql=wikidata.sparql | ||
for wikiId,expected in [("ceur-ws",10),("media",500)]: | ||
wikiUsers = WikiUser.getWikiUsers() | ||
wikidata = Wikidata() | ||
sparql = wikidata.sparql | ||
for wikiId, expected in [("ceur-ws", 10), ("media", 500)]: | ||
if wikiId in wikiUsers: | ||
scholarGrid=ScholarGrid(app=None,wikiUsers=wikiUsers,wikiId=wikiId,sparql=sparql) | ||
scholars=scholarGrid.getScholars() | ||
debug=self.debug | ||
debug=True | ||
scholarGrid = ScholarGrid( | ||
app=None, wikiUsers=wikiUsers, wikiId=wikiId, sparql=sparql | ||
) | ||
scholars = scholarGrid.getScholars() | ||
debug = self.debug | ||
debug = True | ||
if debug: | ||
print(f"found {len(scholars)} scholars in {wikiId} wiki" ) | ||
self.assertTrue(len(scholars)>expected) | ||
print(f"found {len(scholars)} scholars in {wikiId} wiki") | ||
self.assertTrue(len(scholars) > expected) |
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 |
---|---|---|
@@ -1,111 +1,119 @@ | ||
''' | ||
""" | ||
Created on 2022-11-22 | ||
@author: wf | ||
''' | ||
from tests.basetest import Basetest | ||
""" | ||
from ngwidgets.basetest import Basetest | ||
from skg.doi import DOI | ||
from skg.dblp import Dblp | ||
from dataclasses import dataclass | ||
from unittest import IsolatedAsyncioTestCase | ||
import json | ||
|
||
|
||
@dataclass | ||
class DOIExample: | ||
doi: str | ||
isDoi: bool | ||
|
||
|
||
|
||
class TestDOI(Basetest): | ||
""" | ||
test DOI access | ||
""" | ||
|
||
def testDOICheck(self): | ||
""" | ||
check DOI regex | ||
""" | ||
doi_examples=[ | ||
DOIExample("10.1007/11581116_19",True), | ||
DOIExample("10.1109/TBDATA.2022.3224749",True), | ||
DOIExample("xyz",False)] | ||
doi_examples = [ | ||
DOIExample("10.1007/11581116_19", True), | ||
DOIExample("10.1109/TBDATA.2022.3224749", True), | ||
DOIExample("xyz", False), | ||
] | ||
for doi_example in doi_examples: | ||
self.assertTrue(DOI.isDOI(doi_example.doi)==doi_example.isDoi,doi_example.doi) | ||
|
||
self.assertTrue( | ||
DOI.isDOI(doi_example.doi) == doi_example.isDoi, doi_example.doi | ||
) | ||
|
||
def test_dblp_dois(self): | ||
""" | ||
test dblp dois | ||
""" | ||
dblp=Dblp() | ||
limit=5 | ||
debug=True | ||
paper_records=dblp.get_paper_records("CEUR Workshop Proceedings","publishedin",limit=limit,debug=debug) | ||
dblp = Dblp() | ||
limit = 5 | ||
debug = True | ||
paper_records = dblp.get_paper_records( | ||
"CEUR Workshop Proceedings", "publishedin", limit=limit, debug=debug | ||
) | ||
for paper_record in paper_records: | ||
print(paper_record) | ||
|
||
def testDOILookup(self): | ||
""" | ||
test DOI lookup | ||
test DOI lookup | ||
""" | ||
debug=True | ||
dois=["10.1109/TBDATA.2022.3224749"] | ||
expected=["@article{Li_2023,","@inproceedings{Faruqui_2015,"] | ||
for i,doi in enumerate(dois): | ||
doi_obj=DOI(doi) | ||
result=doi_obj.doi2bibTex() | ||
debug = True | ||
dois = ["10.1109/TBDATA.2022.3224749"] | ||
expected = ["@article{Li_2023,", "@inproceedings{Faruqui_2015,"] | ||
for i, doi in enumerate(dois): | ||
doi_obj = DOI(doi) | ||
result = doi_obj.doi2bibTex() | ||
if debug: | ||
print(result) | ||
self.assertTrue(result.startswith(expected[i])) | ||
|
||
def testCiteproc(self): | ||
""" | ||
cite proc lookup | ||
""" | ||
dois=["10.3115/v1/N15-1184", | ||
"10.1007/s13042-022-01686-5", | ||
"10.3390/info13120562", | ||
"10.48550/arXiv.2211.16865"] | ||
debug=True | ||
""" | ||
dois = [ | ||
"10.3115/v1/N15-1184", | ||
"10.1007/s13042-022-01686-5", | ||
"10.3390/info13120562", | ||
"10.48550/arXiv.2211.16865", | ||
] | ||
debug = True | ||
for doi in dois: | ||
doi_obj=DOI(doi) | ||
json_data=doi_obj.doi2Citeproc() | ||
doi_obj = DOI(doi) | ||
json_data = doi_obj.doi2Citeproc() | ||
if debug: | ||
print(json.dumps(json_data,indent=2)) | ||
print(json.dumps(json_data, indent=2)) | ||
self.assertTrue("DOI" in json_data) | ||
self.assertEqual(doi.lower(),json_data["DOI"].lower()) | ||
self.assertEqual(doi.lower(), json_data["DOI"].lower()) | ||
|
||
def testDataCiteLookup(self): | ||
""" | ||
test the dataCite Lookup api | ||
""" | ||
debug=True | ||
dois=["10.5438/0012"] | ||
debug = True | ||
dois = ["10.5438/0012"] | ||
for doi in dois: | ||
doi_obj=DOI(doi) | ||
json_data=doi_obj.dataCiteLookup() | ||
doi_obj = DOI(doi) | ||
json_data = doi_obj.dataCiteLookup() | ||
if debug: | ||
print(json.dumps(json_data,indent=2)) | ||
print(json.dumps(json_data, indent=2)) | ||
self.assertTrue("data" in json_data) | ||
data=json_data["data"] | ||
data = json_data["data"] | ||
self.assertTrue("id" in data) | ||
self.assertEquals(doi,data["id"]) | ||
self.assertEquals(doi, data["id"]) | ||
pass | ||
|
||
|
||
|
||
|
||
def testScite(self): | ||
""" | ||
test Semantic Cite conversion | ||
""" | ||
dois=["10.1007/978-3-031-21595-7_17","10.48550/ARXIV.2211.16865"] | ||
debug=self.debug | ||
dois = ["10.1007/978-3-031-21595-7_17", "10.48550/ARXIV.2211.16865"] | ||
debug = self.debug | ||
for doi in dois: | ||
doi_obj=DOI(doi) | ||
markup=doi_obj.asScite() | ||
doi_obj = DOI(doi) | ||
markup = doi_obj.asScite() | ||
if debug: | ||
print(markup) | ||
self.assertTrue(f"|doi={doi}" in markup) | ||
|
||
#class TestDOILookup(IsolatedAsyncioTestCase): | ||
|
||
|
||
# class TestDOILookup(IsolatedAsyncioTestCase): | ||
# """ | ||
# test DOI lookup | ||
# """ | ||
# """ |
Oops, something went wrong.