Esempio n. 1
0
    def test_error_in_advanced_rendering(self):
        qids = ["Q35185544", "Q34555562", "Q21284234"]
        with self.assertRaises(TypeError):
            with open("tests/config.yaml") as f2:
                config = yaml.load(f2, Loader=yaml.FullLoader)

            wbib.render_dashboard(qids, mode="advanced")
Esempio n. 2
0
    def test_basic_rendering(self):
        qids = ["Q35185544", "Q34555562", "Q21284234"]

        html = wbib.render_dashboard(info=qids,
                                     mode="basic",
                                     filepath="tests/basic.html")
        assert "Demonstration" in html
Esempio n. 3
0
    def test_advanced_rendering(self):
        with open("tests/config.yaml") as f2:
            config = yaml.load(f2, Loader=yaml.FullLoader)

        html = wbib.render_dashboard(config,
                                     mode="advanced",
                                     filepath="tests/advanced.html")

        assert "Advanced Wikidata Bib" in html
Esempio n. 4
0
arr = [md.replace(".md", "") for md in txtfiles]

arr_qid = []
for item in arr:
    if "Q" in item:
        arr_qid.append(item)
arr_qid = [md.replace("./notes/Q", "wd:Q") for md in arr_qid]

readings = "{"
for i in arr_qid:
    readings = readings + " " + i
readings = readings + " }"

with open("index.html", "w") as f:
    html = render_dashboard(readings)
    f.write(html)

g = rdflib.Graph()
result = g.parse("read.ttl", format="ttl")
wb = rdflib.Namespace("https://github.com/lubianat/wikidata_bib/tree/main/")
wbc = rdflib.Namespace(
    "https://github.com/lubianat/wikidata_bib/tree/main/collections/")
wbn = rdflib.Namespace(
    "https://github.com/lubianat/wikidata_bib/tree/main/notes/")
wd = rdflib.Namespace("http://www.wikidata.org/entity/")

qres = g.query("""
    SELECT DISTINCT ?a ?time
       WHERE {
          ?a wb:read_in ?time .
    Gets the best Wikidata candidate from the title of the paper. 
    """
    api_call = f"https://www.wikidata.org/w/api.php?action=wbsearchentities&search={title}&language=en&format=json"
    api_result = requests.get(api_call).json()
    if api_result["success"] == 1:
        return (api_result["search"][0]["id"])


parser = bibtex.Parser()
bibtexFile = parser.parse_file(sys.argv[1])

list_of_qids = []
print("===== Querying Wikidata to get IDs =====")
with open("error_log.txt", "w") as f:
    f.write("Titles that were not found on Wikidata: \n")
    for i in tqdm(bibtexFile.entries):
        title = bibtexFile.entries[i].fields["title"]
        title = title.replace("{", "")
        title = title.replace("}", "")
        try:
            list_of_qids.append(get_qid_for_title(title))
        except:
            tqdm.write(f"Failed for {title}")
            f.write(f"{title}\n")
        time.sleep(0.3)

formatted_readings = format_ids(list_of_qids)
with open("index.html", "w") as f:
    html = render_dashboard(formatted_readings)
    f.write(html)
    """
    Gets the best Wikidata candidate from the title of the paper. 
    """
    api_call = f"https://www.wikidata.org/w/api.php?action=wbsearchentities&search={title}&language=en&format=json"
    api_result = requests.get(api_call).json()
    if api_result["success"] == 1:
        return (api_result["search"][0]["id"])


parser = bibtex.Parser()
bibtexFile = parser.parse_file(sys.argv[1])

list_of_qids = []
print("===== Querying Wikidata to get IDs =====")
with open("error_log.txt", "w") as f:
    f.write("Titles that were not found on Wikidata: \n")
    for i in tqdm(bibtexFile.entries):
        title = bibtexFile.entries[i].fields["title"]
        title = title.replace("{", "")
        title = title.replace("}", "")
        try:
            list_of_qids.append(get_qid_for_title(title))
        except:
            tqdm.write(f"Failed for {title}")
            f.write(f"{title}\n")
        time.sleep(0.3)

with open("index.html", "w") as f:
    html = wbib.render_dashboard(list_of_qids)
    f.write(html)