Skip to content

Commit 17d1344

Browse files
committed
Refactor code for improved readability and consistency
1 parent dc593e9 commit 17d1344

19 files changed

Lines changed: 643 additions & 400 deletions

File tree

biii-import/biseEU_LD_export.py

Lines changed: 89 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def rdfize_bioschema_tool(json_entry):
412412

413413
for item in entry["field_has_function"]:
414414
if "target_uuid" in item.keys():
415-
if not "featureList" in out.keys():
415+
if "featureList" not in out.keys():
416416
out["featureList"] = [{"@id": item["target_uuid"]}]
417417
else:
418418
out["featureList"].append({"@id": item["target_uuid"]})
@@ -424,29 +424,29 @@ def rdfize_bioschema_tool(json_entry):
424424

425425
for item in entry["field_has_topic"]:
426426
if "target_uuid" in item.keys():
427-
if not "hasTopic" in out.keys():
427+
if "hasTopic" not in out.keys():
428428
out["hasTopic"] = [{"@id": item["target_uuid"]}]
429429
# print(f"Added first topic {item['target_uuid']}")
430430
else:
431431
out["hasTopic"].append({"@id": item["target_uuid"]})
432432
# print(f"Added another topic {item['target_uuid']}")
433433

434434
for item in entry["field_has_reference_publication"]:
435-
if not "citation" in out.keys():
435+
if "citation" not in out.keys():
436436
out["citation"] = []
437437
if item["uri"]:
438438
out["citation"].append({"@id": item["uri"].strip()})
439439
if item["title"]:
440440
out["citation"].append(item["title"])
441441

442442
for item in entry["field_has_license"]:
443-
if not "license" in out.keys():
443+
if "license" not in out.keys():
444444
out["license"] = []
445445
if item["value"]:
446446
out["license"].append(item["value"])
447447

448448
for item in entry["field_has_author"]:
449-
if not "publisher" in out.keys():
449+
if "publisher" not in out.keys():
450450
out["publisher"] = []
451451
if item["value"]:
452452
out["publisher"].append(item["value"])
@@ -462,12 +462,12 @@ def rdfize_bioschema_tool(json_entry):
462462
out["dateModified"] = str(date.isoformat())
463463

464464
for item in entry["field_is_dependent_of"]:
465-
if not "softwareRequirements" in out.keys():
465+
if "softwareRequirements" not in out.keys():
466466
out["softwareRequirements"] = []
467467
if item["target_id"]:
468-
out["softwareRequirements"].append({
469-
"@id": "http://biii.eu/node/" + str(item["target_id"]).strip()
470-
})
468+
out["softwareRequirements"].append(
469+
{"@id": "http://biii.eu/node/" + str(item["target_id"]).strip()}
470+
)
471471

472472
out.update(ctx)
473473

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

538538
for item in entry["field_image"]:
539-
if not "hasIllustration" in entry.keys():
539+
if "hasIllustration" not in entry.keys():
540540
entry["hasIllustration"] = [item["url"]]
541541
else:
542542
entry["hasIllustration"].append(item["url"])
543543

544544
for item in entry["field_has_author"]:
545-
if not "hasAuthor" in entry.keys():
545+
if "hasAuthor" not in entry.keys():
546546
entry["hasAuthor"] = []
547547
if item["value"]:
548548
entry["hasAuthor"].append(item["value"])
@@ -553,190 +553,208 @@ def rdfize(json_entry):
553553
for item in entry["field_has_function"]:
554554
# print(item)
555555
if "target_uuid" in item.keys():
556-
if not "hasFunction" in entry.keys():
556+
if "hasFunction" not in entry.keys():
557557
entry["hasFunction"] = [{"@id": item["target_uuid"]}]
558558
else:
559559
entry["hasFunction"].append({"@id": item["target_uuid"]})
560560

561561
for item in entry["field_has_topic"]:
562562
# print(item)
563563
if "target_uuid" in item.keys():
564-
if not "hasTopic" in entry.keys():
564+
if "hasTopic" not in entry.keys():
565565
entry["hasTopic"] = [{"@id": item["target_uuid"]}]
566566
else:
567567
entry["hasTopic"].append({"@id": item["target_uuid"]})
568568

569569
for item in entry["field_is_dependent_of"]:
570570
# print(item)
571571
if "target_id" in item.keys():
572-
if not "requires" in entry.keys():
572+
if "requires" not in entry.keys():
573573
entry["requires"] = [
574574
{"@id": "http://biii.eu/node/" + str(item["target_id"])}
575575
]
576576
else:
577-
entry["requires"].append({
578-
"@id": "http://biii.eu/node/" + str(item["target_id"])
579-
})
577+
entry["requires"].append(
578+
{"@id": "http://biii.eu/node/" + str(item["target_id"])}
579+
)
580580

581581
for item in entry["field_has_reference_publication"]:
582-
if not "citation" in entry.keys():
582+
if "citation" not in entry.keys():
583583
entry["citation"] = []
584584
if item["uri"]:
585-
entry["citation"].append({
586-
"@id": urllib.parse.quote(item["uri"], safe=":/")
587-
})
585+
entry["citation"].append(
586+
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
587+
)
588588
if item["title"]:
589589
entry["citation"].append(item["title"])
590590

591591
for item in entry["field_has_location"]:
592-
if not "location" in entry.keys():
592+
if "location" not in entry.keys():
593593
entry["location"] = []
594594
if item["uri"]:
595-
entry["location"].append({
596-
"@id": urllib.parse.quote(item["uri"], safe=":/")
597-
})
595+
entry["location"].append(
596+
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
597+
)
598598
if item["title"]:
599599
entry["location"].append(item["title"])
600600

601601
for item in entry["field_has_license"]:
602-
if not "license" in entry.keys():
602+
if "license" not in entry.keys():
603603
entry["license"] = []
604604
if item["value"]:
605605
entry["license"].append(item["value"])
606606

607607
for item in entry["field_license_openness"]:
608608
if "target_id" in item.keys():
609-
if not "openess" in entry.keys():
609+
if "openess" not in entry.keys():
610610
entry["openess"] = [
611611
{
612612
"@id": "http://biii.eu/taxonomy/term/"
613613
+ str(item["target_id"])
614614
}
615615
]
616616
else:
617-
entry["openess"].append({
618-
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
619-
})
617+
entry["openess"].append(
618+
{
619+
"@id": "http://biii.eu/taxonomy/term/"
620+
+ str(item["target_id"])
621+
}
622+
)
620623

621624
for item in entry["field_has_implementation"]:
622625
# print(item)
623626
if "target_id" in item.keys():
624-
if not "hasImplementation" in entry.keys():
627+
if "hasImplementation" not in entry.keys():
625628
entry["hasImplementation"] = [
626629
{
627630
"@id": "http://biii.eu/taxonomy/term/"
628631
+ str(item["target_id"])
629632
}
630633
]
631634
else:
632-
entry["hasImplementation"].append({
633-
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
634-
})
635+
entry["hasImplementation"].append(
636+
{
637+
"@id": "http://biii.eu/taxonomy/term/"
638+
+ str(item["target_id"])
639+
}
640+
)
635641

636642
for item in entry["field_type"]:
637643
if "target_id" in item.keys():
638-
if not "hasType" in entry.keys():
644+
if "hasType" not in entry.keys():
639645
entry["hasType"] = [
640646
{
641647
"@id": "http://biii.eu/taxonomy/term/"
642648
+ str(item["target_id"])
643649
}
644650
]
645651
else:
646-
entry["hasType"].append({
647-
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
648-
})
652+
entry["hasType"].append(
653+
{
654+
"@id": "http://biii.eu/taxonomy/term/"
655+
+ str(item["target_id"])
656+
}
657+
)
649658

650659
for item in entry["field_has_programming_language"]:
651660
if "target_id" in item.keys():
652-
if not "hasProgrammingLanguage" in entry.keys():
661+
if "hasProgrammingLanguage" not in entry.keys():
653662
entry["hasProgrammingLanguage"] = [
654663
{
655664
"@id": "http://biii.eu/taxonomy/term/"
656665
+ str(item["target_id"])
657666
}
658667
]
659668
else:
660-
entry["hasProgrammingLanguage"].append({
661-
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
662-
})
669+
entry["hasProgrammingLanguage"].append(
670+
{
671+
"@id": "http://biii.eu/taxonomy/term/"
672+
+ str(item["target_id"])
673+
}
674+
)
663675

664676
for item in entry["field_platform"]:
665677
if "target_id" in item.keys():
666-
if not "hasPlatform" in entry.keys():
678+
if "hasPlatform" not in entry.keys():
667679
entry["hasPlatform"] = [
668680
{
669681
"@id": "http://biii.eu/taxonomy/term/"
670682
+ str(item["target_id"])
671683
}
672684
]
673685
else:
674-
entry["hasPlatform"].append({
675-
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
676-
})
686+
entry["hasPlatform"].append(
687+
{
688+
"@id": "http://biii.eu/taxonomy/term/"
689+
+ str(item["target_id"])
690+
}
691+
)
677692

678693
for item in entry["field_supported_image_dimension"]:
679694
if "target_id" in item.keys():
680-
if not "hasSupportedImageDimension" in entry.keys():
695+
if "hasSupportedImageDimension" not in entry.keys():
681696
entry["hasSupportedImageDimension"] = [
682697
{
683698
"@id": "http://biii.eu/taxonomy/term/"
684699
+ str(item["target_id"])
685700
}
686701
]
687702
else:
688-
entry["hasSupportedImageDimension"].append({
689-
"@id": "http://biii.eu/taxonomy/term/" + str(item["target_id"])
690-
})
703+
entry["hasSupportedImageDimension"].append(
704+
{
705+
"@id": "http://biii.eu/taxonomy/term/"
706+
+ str(item["target_id"])
707+
}
708+
)
691709

692710
for item in entry["field_is_covered_by_training_mat"]:
693711
if "target_id" in item.keys():
694-
if not "hasTrainingMaterial" in entry.keys():
712+
if "hasTrainingMaterial" not in entry.keys():
695713
entry["hasTrainingMaterial"] = [
696714
{"@id": "http://biii.eu/node/" + str(item["target_id"])}
697715
]
698716
else:
699-
entry["hasTrainingMaterial"].append({
700-
"@id": "http://biii.eu/node/" + str(item["target_id"])
701-
})
717+
entry["hasTrainingMaterial"].append(
718+
{"@id": "http://biii.eu/node/" + str(item["target_id"])}
719+
)
702720

703721
for item in entry["field_has_documentation"]:
704-
if not "uri" in entry.keys():
722+
if "uri" not in entry.keys():
705723
entry["hasDocumentation"] = []
706724
if item["uri"]:
707-
entry["hasDocumentation"].append({
708-
"@id": urllib.parse.quote(item["uri"], safe=":/")
709-
})
725+
entry["hasDocumentation"].append(
726+
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
727+
)
710728
if item["title"]:
711729
entry["hasDocumentation"].append(item["title"])
712730

713731
for item in entry["field_has_comparison"]:
714-
if not "uri" in entry.keys():
732+
if "uri" not in entry.keys():
715733
entry["hasComparison"] = []
716734
if item["uri"]:
717-
entry["hasComparison"].append({
718-
"@id": urllib.parse.quote(item["uri"], safe=":/")
719-
})
735+
entry["hasComparison"].append(
736+
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
737+
)
720738
if item["title"]:
721739
entry["hasComparison"].append(item["title"])
722740

723741
for item in entry["field_has_usage_example"]:
724-
if not "uri" in entry.keys():
742+
if "uri" not in entry.keys():
725743
entry["hasUsageExample"] = []
726744
if item["uri"]:
727-
entry["hasUsageExample"].append({
728-
"@id": urllib.parse.quote(item["uri"], safe=":/")
729-
})
745+
entry["hasUsageExample"].append(
746+
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
747+
)
730748
if item["title"]:
731749
entry["hasUsageExample"].append(item["title"])
732750

733751
for item in entry["field_has_doi"]:
734-
if not "uri" in entry.keys():
752+
if "uri" not in entry.keys():
735753
entry["hasDOI"] = []
736754
if item["uri"]:
737-
entry["hasDOI"].append({
738-
"@id": urllib.parse.quote(item["uri"], safe=":/")
739-
})
755+
entry["hasDOI"].append(
756+
{"@id": urllib.parse.quote(item["uri"], safe=":/")}
757+
)
740758
if item["title"]:
741759
entry["hasDOI"].append(item["title"])
742760

@@ -796,7 +814,7 @@ def get_software_list(connection):
796814
except urllib3.exceptions.HTTPError as e:
797815
print("Connection error")
798816
print(e)
799-
except json.decoder.JSONDecodeError as e:
817+
except json.decoder.JSONDecodeError:
800818
print(f"Contents are not propertly formatted in {req.geturl()}")
801819
print("Response contents:", req.data)
802820
return None

0 commit comments

Comments
 (0)