Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 89 additions & 71 deletions biii-import/biseEU_LD_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def rdfize_bioschema_tool(json_entry):

for item in entry["field_has_function"]:
if "target_uuid" in item.keys():
if not "featureList" in out.keys():
if "featureList" not in out.keys():
out["featureList"] = [{"@id": item["target_uuid"]}]
else:
out["featureList"].append({"@id": item["target_uuid"]})
Expand All @@ -424,29 +424,29 @@ def rdfize_bioschema_tool(json_entry):

for item in entry["field_has_topic"]:
if "target_uuid" in item.keys():
if not "hasTopic" in out.keys():
if "hasTopic" not in out.keys():
out["hasTopic"] = [{"@id": item["target_uuid"]}]
# print(f"Added first topic {item['target_uuid']}")
else:
out["hasTopic"].append({"@id": item["target_uuid"]})
# print(f"Added another topic {item['target_uuid']}")

for item in entry["field_has_reference_publication"]:
if not "citation" in out.keys():
if "citation" not in out.keys():
out["citation"] = []
if item["uri"]:
out["citation"].append({"@id": item["uri"].strip()})
if item["title"]:
out["citation"].append(item["title"])

for item in entry["field_has_license"]:
if not "license" in out.keys():
if "license" not in out.keys():
out["license"] = []
if item["value"]:
out["license"].append(item["value"])

for item in entry["field_has_author"]:
if not "publisher" in out.keys():
if "publisher" not in out.keys():
out["publisher"] = []
if item["value"]:
out["publisher"].append(item["value"])
Expand All @@ -462,12 +462,12 @@ def rdfize_bioschema_tool(json_entry):
out["dateModified"] = str(date.isoformat())

for item in entry["field_is_dependent_of"]:
if not "softwareRequirements" in out.keys():
if "softwareRequirements" not in out.keys():
out["softwareRequirements"] = []
if item["target_id"]:
out["softwareRequirements"].append({
"@id": "http://biii.eu/node/" + str(item["target_id"]).strip()
})
out["softwareRequirements"].append(
{"@id": "http://biii.eu/node/" + str(item["target_id"]).strip()}
)

out.update(ctx)

Expand Down Expand Up @@ -536,13 +536,13 @@ def rdfize(json_entry):
entry["hasTitle"] = entry["title"][0]["value"]

for item in entry["field_image"]:
if not "hasIllustration" in entry.keys():
if "hasIllustration" not in entry.keys():
entry["hasIllustration"] = [item["url"]]
else:
entry["hasIllustration"].append(item["url"])

for item in entry["field_has_author"]:
if not "hasAuthor" in entry.keys():
if "hasAuthor" not in entry.keys():
entry["hasAuthor"] = []
if item["value"]:
entry["hasAuthor"].append(item["value"])
Expand All @@ -553,190 +553,208 @@ def rdfize(json_entry):
for item in entry["field_has_function"]:
# print(item)
if "target_uuid" in item.keys():
if not "hasFunction" in entry.keys():
if "hasFunction" not in entry.keys():
entry["hasFunction"] = [{"@id": item["target_uuid"]}]
else:
entry["hasFunction"].append({"@id": item["target_uuid"]})

for item in entry["field_has_topic"]:
# print(item)
if "target_uuid" in item.keys():
if not "hasTopic" in entry.keys():
if "hasTopic" not in entry.keys():
entry["hasTopic"] = [{"@id": item["target_uuid"]}]
else:
entry["hasTopic"].append({"@id": item["target_uuid"]})

for item in entry["field_is_dependent_of"]:
# print(item)
if "target_id" in item.keys():
if not "requires" in entry.keys():
if "requires" not in entry.keys():
entry["requires"] = [
{"@id": "http://biii.eu/node/" + str(item["target_id"])}
]
else:
entry["requires"].append({
"@id": "http://biii.eu/node/" + str(item["target_id"])
})
entry["requires"].append(
{"@id": "http://biii.eu/node/" + str(item["target_id"])}
)

for item in entry["field_has_reference_publication"]:
if not "citation" in entry.keys():
if "citation" not in entry.keys():
entry["citation"] = []
if item["uri"]:
entry["citation"].append({
"@id": urllib.parse.quote(item["uri"], safe=":/")
})
entry["citation"].append(
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
)
if item["title"]:
entry["citation"].append(item["title"])

for item in entry["field_has_location"]:
if not "location" in entry.keys():
if "location" not in entry.keys():
entry["location"] = []
if item["uri"]:
entry["location"].append({
"@id": urllib.parse.quote(item["uri"], safe=":/")
})
entry["location"].append(
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
)
if item["title"]:
entry["location"].append(item["title"])

for item in entry["field_has_license"]:
if not "license" in entry.keys():
if "license" not in entry.keys():
entry["license"] = []
if item["value"]:
entry["license"].append(item["value"])

for item in entry["field_license_openness"]:
if "target_id" in item.keys():
if not "openess" in entry.keys():
if "openess" not in entry.keys():
entry["openess"] = [
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
]
else:
entry["openess"].append({
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
})
entry["openess"].append(
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
)

for item in entry["field_has_implementation"]:
# print(item)
if "target_id" in item.keys():
if not "hasImplementation" in entry.keys():
if "hasImplementation" not in entry.keys():
entry["hasImplementation"] = [
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
]
else:
entry["hasImplementation"].append({
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
})
entry["hasImplementation"].append(
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
)

for item in entry["field_type"]:
if "target_id" in item.keys():
if not "hasType" in entry.keys():
if "hasType" not in entry.keys():
entry["hasType"] = [
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
]
else:
entry["hasType"].append({
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
})
entry["hasType"].append(
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
)

for item in entry["field_has_programming_language"]:
if "target_id" in item.keys():
if not "hasProgrammingLanguage" in entry.keys():
if "hasProgrammingLanguage" not in entry.keys():
entry["hasProgrammingLanguage"] = [
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
]
else:
entry["hasProgrammingLanguage"].append({
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
})
entry["hasProgrammingLanguage"].append(
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
)

for item in entry["field_platform"]:
if "target_id" in item.keys():
if not "hasPlatform" in entry.keys():
if "hasPlatform" not in entry.keys():
entry["hasPlatform"] = [
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
]
else:
entry["hasPlatform"].append({
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
})
entry["hasPlatform"].append(
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
)

for item in entry["field_supported_image_dimension"]:
if "target_id" in item.keys():
if not "hasSupportedImageDimension" in entry.keys():
if "hasSupportedImageDimension" not in entry.keys():
entry["hasSupportedImageDimension"] = [
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
]
else:
entry["hasSupportedImageDimension"].append({
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
})
entry["hasSupportedImageDimension"].append(
{
"@id": "http://biii.eu/taxonomy/term/"
+ str(item["target_id"])
}
)

for item in entry["field_is_covered_by_training_mat"]:
if "target_id" in item.keys():
if not "hasTrainingMaterial" in entry.keys():
if "hasTrainingMaterial" not in entry.keys():
entry["hasTrainingMaterial"] = [
{"@id": "http://biii.eu/node/" + str(item["target_id"])}
]
else:
entry["hasTrainingMaterial"].append({
"@id": "http://biii.eu/node/" + str(item["target_id"])
})
entry["hasTrainingMaterial"].append(
{"@id": "http://biii.eu/node/" + str(item["target_id"])}
)

for item in entry["field_has_documentation"]:
if not "uri" in entry.keys():
if "uri" not in entry.keys():
entry["hasDocumentation"] = []
if item["uri"]:
entry["hasDocumentation"].append({
"@id": urllib.parse.quote(item["uri"], safe=":/")
})
entry["hasDocumentation"].append(
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
)
if item["title"]:
entry["hasDocumentation"].append(item["title"])

for item in entry["field_has_comparison"]:
if not "uri" in entry.keys():
if "uri" not in entry.keys():
entry["hasComparison"] = []
if item["uri"]:
entry["hasComparison"].append({
"@id": urllib.parse.quote(item["uri"], safe=":/")
})
entry["hasComparison"].append(
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
)
if item["title"]:
entry["hasComparison"].append(item["title"])

for item in entry["field_has_usage_example"]:
if not "uri" in entry.keys():
if "uri" not in entry.keys():
entry["hasUsageExample"] = []
if item["uri"]:
entry["hasUsageExample"].append({
"@id": urllib.parse.quote(item["uri"], safe=":/")
})
entry["hasUsageExample"].append(
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
)
if item["title"]:
entry["hasUsageExample"].append(item["title"])

for item in entry["field_has_doi"]:
if not "uri" in entry.keys():
if "uri" not in entry.keys():
entry["hasDOI"] = []
if item["uri"]:
entry["hasDOI"].append({
"@id": urllib.parse.quote(item["uri"], safe=":/")
})
entry["hasDOI"].append(
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
)
if item["title"]:
entry["hasDOI"].append(item["title"])

Expand Down Expand Up @@ -796,7 +814,7 @@ def get_software_list(connection):
except urllib3.exceptions.HTTPError as e:
print("Connection error")
print(e)
except json.decoder.JSONDecodeError as e:
except json.decoder.JSONDecodeError:
print(f"Contents are not propertly formatted in {req.geturl()}")
print("Response contents:", req.data)
return None
Expand Down
Loading