Skip to content

Commit

Permalink
Merge pull request #207 from IFB-ElixirFr/bug-json-ld
Browse files Browse the repository at this point in the history
fixed JSON-LD parsing
  • Loading branch information
albangaignard authored Oct 31, 2023
2 parents 5cbb2dd + 7a499cf commit 7e857bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 3 additions & 8 deletions metrics/WebResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,36 +488,31 @@ def html_to_rdf_extruct(self, html_source) -> ConjunctiveGraph:
)

kg_jsonld = ConjunctiveGraph()

if "json-ld" in data.keys():
for md in data["json-ld"]:
kg_jsonld.parse(
kg_jsonld += kg_jsonld.parse(
data=json.dumps(md, ensure_ascii=False),
format="json-ld",
publicID=self.url,
)

kg_rdfa = ConjunctiveGraph()

if "rdfa" in data.keys():
for md in data["rdfa"]:
kg_rdfa.parse(
kg_rdfa += kg_rdfa.parse(
data=json.dumps(md, ensure_ascii=False),
format="json-ld",
publicID=self.url,
)
# print(len(kg_rdfa))

kg_microdata = ConjunctiveGraph()

if "microdata" in data.keys():
for md in data["microdata"]:
kg_microdata.parse(
kg_microdata += kg_microdata.parse(
data=json.dumps(md, ensure_ascii=False),
format="json-ld",
publicID=self.url,
)
# print(len(kg_microdata))

kg_extruct = kg_jsonld + kg_rdfa + kg_microdata

Expand Down
7 changes: 7 additions & 0 deletions tests/test_web_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ def test_turtle(self):
logging.info(f"{len(turtle_WR.get_rdf())} loaded RDF triples")
# self.assertEqual(60, len(turtle_WR.get_rdf()))

def test_MassBank(self):
mb = WebResource("https://massbank.eu/MassBank/RecordDisplay?id=MSBNK-RIKEN_IMS-LQB00001")
kg = mb.get_rdf()
#print(kg.serialize(format="turtle"))
#logging.info(f"{len(kg)} loaded RDF triples")
self.assertGreater(len(kg), 70)

def test_n3(self):
n3_WR = WebResource("https://www.w3.org/2002/11/rddl/ex1.n3")
logging.info(f"{len(n3_WR.get_rdf())} loaded RDF triples")
Expand Down

0 comments on commit 7e857bf

Please sign in to comment.