-
Notifications
You must be signed in to change notification settings - Fork 1
Adding Concepts
You can use CreateSKOSSimpler
to create new concepts and add this into the collection
# compile-time
from conveyance import get_conveyance
conveyance = get_conveyance()
conveyance.code = "coral/admin-create-skos:1"
conveyance.description = "Build the SKOS files"
conveyance.requirements = [
"rdflib",
"arches_graphql_client @ git+https://github.com/flaxandteal/arches_graphql_client@main",
"arches-orm @ git+https://github.com/flaxandteal/arches-orm@feature/simple-static-rdm-update"
]
conveyance.data_files_to_version = [
"FISH/terminology-hierarchy.xlsx"
]
conveyance.install_dependencies(preuninstall=["arches_graphql_client", "arches-orm"])
Conveyance is used throughout when reading and writing. This is a script written to allow this to be run and applied to production
In this cell we import several elements. The main concern here is data_files_to_version
if you need to import a file to parse data from you must add it here for the conveyance to be able to read it
with conveyance.read("FISH/terminology-hierarchy.xlsx", False, "rb") as f:
modified_fish_monuments = pd.read_excel(f)
modified_fish_monuments_list = list(modified_fish_monuments["FISH/ Proposed General Term"].dropna().unique())
cleaned_modified_fish_monuments_list = sorted(set([
fish.replace('?', '')
.title()
for fish in modified_fish_monuments_list]))
print(cleaned_modified_fish_monuments_list)
Here we are reading an excel file and grabbing a column of data and cleaning it into a list When reading with the conveyance you need to set False when reading from an existing file and set True when writing a file.
import pytest
from pathlib import Path
from shutil import copyfile
from arches_orm import static
from arches_orm.adapter import context_free, get_adapter
copyfile("fat_collections.xml", "fat_simple_collections.xml")
rdm = get_adapter().get_rdm()
monument_concept_list = []
for name in cleaned_modified_fish_monuments_list:
concept = rdm.make_simple_concept("FISH_Proposed_General_Terms", name)
monument_concept_list.append(concept)
general_term_concept = rdm.make_simple_concept("FISH_Proposed_General_Terms", "FISH Proposed General Terms", children=monument_concept_list)
general_term_collection = rdm.concept_to_collection(general_term_concept)
rdm.save_concept(general_term_concept, "FISH_Proposed_General_Terms.xml")
rdm.update_collections(general_term_collection, Path("fat_simple_collections.xml"))
# concept_1 = rdm.make_simple_concept("Townlands", "Townland1")
# concept_2 = rdm.make_simple_concept("Townlands", "Townland2")
# my_status = rdm.make_simple_concept("Townlands", children=[concept_1, concept_2])
# MyStatusEnum = rdm.concept_to_collection(my_status)
make_simple_concept(Namespace:string, value:string, children:[concepts])
- First run each item in your list through the function, setting the namespace and the value
- Append to a list
- Run
make_simple_concept
again. Set the namespace as before, set the value to the name you wish to use for the concept, set the children as the list of concepts you created - Run
concept_to_collection
setting your new concept as the argument
rdm.save_concept(general_term_concept, "FISH_Proposed_General_Terms.xml")
rdm.update_collections(general_term_collection, Path("fat_simple_collections.xml"))
We then save our collections to a new file
fat_simple_collections.xml
has the fat_collections.xml
written into it at the start of the cell
ConceptClient = arches_graphql_client.concept.ConceptClient
concept_client = ConceptClient(ENDPOINT)
concept_client.connect(timeout=1000)
with conveyance.read("FISH_Proposed_General_Terms.xml", True, "rb") as fd:
fish_success = await concept_client.replace_from_skos(fd)
print(aa_success)
with conveyance.read("fat_simple_collections.xml", True, "rb") as fd:
# This doesn't create a concept so comes back False if it's ok :/
await concept_client.replace_from_skos(fd)
This will write the new collection and concept to dev
Here we need to set True
for the conveyance to work correctly