diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 4e147c2..52bcfaa 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -1,4 +1,4 @@ -name: CI - Tests +name: EMMO check on: [pull_request] @@ -24,16 +24,32 @@ jobs: - name: Run EMMO Check - battery run: | - emmocheck --verbose --url-from-catalog \ - --skip test_namespace \ - --skip test_quantity_dimension \ - --configfile=.github/utils/emmocheck_config.yml \ - battery.ttl + if [ -f "battery.ttl" ]; then + emmocheck --verbose --url-from-catalog \ + --skip test_namespace \ + --skip test_quantity_dimension \ + --configfile=.github/utils/emmocheck_config.yml \ + battery.ttl + else + echo "battery.ttl not found!" + exit 1 + fi - name: Run EMMO Check - batteryquantities run: | - emmocheck --verbose --url-from-catalog \ - --skip test_namespace \ - --skip test_quantity_dimension \ - --configfile=.github/utils/emmocheck_config.yml \ - batteryquantities.ttl + if [ -f "batteryquantities.ttl" ]; then + emmocheck --verbose --url-from-catalog \ + --skip test_namespace \ + --skip test_quantity_dimension \ + --configfile=.github/utils/emmocheck_config.yml \ + batteryquantities.ttl + elif [ -f "modules/quantities.ttl" ]; then + emmocheck --verbose --url-from-catalog \ + --skip test_namespace \ + --skip test_quantity_dimension \ + --configfile=.github/utils/emmocheck_config.yml \ + modules/quantities.ttl + else + echo "batteryquantities.ttl or modules/quantities.ttl not found!" + exit 1 + fi diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index b139df3..c0f92a5 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -4,7 +4,10 @@ on: push: branches: - 'master' - + pull_request: + branches: + - '*' # To ensure it runs on all PRs + env: GIT_USER_NAME: BattINFO Developers GIT_USER_EMAIL: "BattINFO@big-map.org" @@ -23,14 +26,14 @@ jobs: uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 #Uses python install action from here: https://github.com/marketplace?type=actions + uses: actions/setup-python@v4 with: - python-version: '3.10' # Replace with the desired Python version + python-version: '3.10' - name: Install dependencies run: | python -m pip install --upgrade pip - pip install Markdown==3.4.3 rdflib==6.3.2 # Add any other dependencies if needed + pip install Markdown==3.4.3 rdflib==6.3.2 pandoc - name: Render documentation from ttl run: python docs/scripts/ttl_to_rst.py @@ -40,25 +43,24 @@ jobs: with: docs-folder: "docs/" pre-build-command: "apt-get update -y; apt-get install -y pandoc" - + - name: Create context file from ttl run: python docs/scripts/ttl_to_context.py - name: Check if HTML context directory exists run: | if [ ! -d "docs/_build/html/context/" ]; then - echo "Creating HTML context directory" sudo mkdir -p docs/_build/html/context/ - else - echo "HTML context directory already exists" fi - + if [ ! -d "docs/_build/html/assets/" ]; then + sudo mkdir -p docs/_build/html/assets/ + fi if [ ! -d "docs/_build/html/versions/" ]; then - echo "Creating HTML versions directory" sudo mkdir -p docs/_build/html/versions/ - else - echo "HTML versions directory already exists" fi + + - name: Copy assets directory to HTML directory + run: sudo cp -r docs/assets/* docs/_build/html/assets/ - name: Copy context file to HTML directory run: sudo cp context/context.json docs/_build/html/context/ @@ -68,10 +70,14 @@ jobs: git config --local user.email "${{ env.GIT_USER_EMAIL }}" git config --local user.name "${{ env.GIT_USER_NAME }}" git add context/context.json - # Check for any changes to commit git diff --staged --quiet || git commit -m "Update context.json file" + - name: Pull latest changes + if: github.event_name == 'push' # Only pull changes during push events + run: git pull origin master --rebase + - name: Push changes + if: github.event_name == 'push' && github.ref == 'refs/heads/master' # Only push during push events on master run: git push origin HEAD:master - name: Fetch all tags and create version directories @@ -79,31 +85,45 @@ jobs: git fetch --tags git tag | while read TAG; do sudo mkdir -p "docs/_build/html/versions/$TAG" + + if [ -f "batteryquantities.ttl" ]; then + python docs/scripts/apply_foops_recommendations.py batteryquantities.ttl batteryquantities-foops.ttl + sudo cp "batteryquantities-foops.ttl" "docs/_build/html/versions/$TAG/batteryquantities.ttl" + elif [ -f "modules/quantities.ttl" ]; then + python docs/scripts/apply_foops_recommendations.py modules/quantities.ttl quantities-foops.ttl + sudo cp "quantities-foops.ttl" "docs/_build/html/versions/$TAG/quantities.ttl" + else + echo "File not found!" + exit 1 + fi + python docs/scripts/apply_foops_recommendations.py battery.ttl battery-foops.ttl - python docs/scripts/apply_foops_recommendations.py batteryquantities.ttl batteryquantities-foops.ttl - sudo cp "battery-foops.ttl" "docs/_build/html/versions/$TAG/" - sudo cp "batteryquantities-foops.ttl" "docs/_build/html/versions/$TAG/" + sudo cp "battery-foops.ttl" "docs/_build/html/versions/$TAG/battery.ttl" sudo cp "battery-inferred.ttl" "docs/_build/html/versions/$TAG/" - if [ -d "context" ]; then - echo "Context directory exists, copying context.json to $TAG" - # Make sure the context directory exists in the version-specific directory - sudo mkdir -p "docs/_build/html/versions/$TAG/context" - # Copy context.json to the tag-specific context directory - sudo cp "context/context.json" "docs/_build/html/versions/$TAG/context" - else - echo "No context directory found in the source directory." - fi + if [ -d "context" ]; then + sudo mkdir -p "docs/_build/html/versions/$TAG/context" + sudo cp "context/context.json" "docs/_build/html/versions/$TAG/context" + fi done - name: Copy TTL files to HTML directory run: | + if [ -f "batteryquantities.ttl" ]; then + python docs/scripts/apply_foops_recommendations.py batteryquantities.ttl batteryquantities-foops.ttl + sudo cp "batteryquantities-foops.ttl" "docs/_build/html/batteryquantities.ttl" + elif [ -f "modules/quantities.ttl" ]; then + python docs/scripts/apply_foops_recommendations.py modules/quantities.ttl quantities-foops.ttl + sudo cp "quantities-foops.ttl" "docs/_build/html/quantities.ttl" + else + echo "battery quantities file not found!" + exit 1 + fi + python docs/scripts/apply_foops_recommendations.py battery.ttl battery-foops.ttl - python docs/scripts/apply_foops_recommendations.py batteryquantities.ttl batteryquantities-foops.ttl sudo cp "battery-foops.ttl" "docs/_build/html/battery.ttl" - sudo cp "batteryquantities-foops.ttl" "docs/_build/html/batteryquantities.ttl" sudo cp "battery-inferred.ttl" "docs/_build/html/battery-inferred.ttl" - + - name: Upload artifacts uses: actions/upload-artifact@v4 with: @@ -111,10 +131,8 @@ jobs: path: docs/_build/html/ - name: Deploy + if: github.ref == 'refs/heads/master' && github.event_name == 'push' # Only deploy during push events on master uses: peaceiris/actions-gh-pages@v3 - if: github.ref == 'refs/heads/master' with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: docs/_build/html - - diff --git a/battery.ttl b/battery.ttl index 2fcc2cc..94b1514 100644 --- a/battery.ttl +++ b/battery.ttl @@ -17,9 +17,9 @@ @base . rdf:type owl:Ontology ; - owl:versionIRI ; - owl:imports , - ; + owl:versionIRI ; + owl:imports , + ; dcterms:abstract "The Battery Domain Ontology, a specialized domain within the Elementary Multiperspective Materials Ontology (EMMO), encompasses essential terms and relationships for battery components, cells, interfaces, methods, models, and data. Its primary objective is to enable the creation of linked and FAIR (Findable, Accessible, Interoperable, and Reusable) data, thereby fostering advancements in research and innovation within the realm of batteries. This ontology serves as a foundational resource for harmonizing battery knowledge representation, enhancing data interoperability, and accelerating progress in battery research and development." ; dcterms:bibliographicCitation "https://zenodo.org/doi/10.5281/zenodo.7693672" ; dcterms:contributor , @@ -28,9 +28,9 @@ dcterms:created "2022-11-25"^^xsd:date ; dcterms:creator , ; - dcterms:issued "2024-07-24"^^xsd:date ; + dcterms:issued "2024-09-15"^^xsd:date ; dcterms:license "https://creativecommons.org/licenses/by/4.0/legalcode" ; - dcterms:modified "2024-07-24"^^xsd:date ; + dcterms:modified "2024-09-15"^^xsd:date ; dcterms:publisher "EMMO" ; dcterms:source ; dcterms:title "Battery Domain Ontology"@en ; @@ -38,9 +38,9 @@ bibo:status "unstable" ; vann:preferredNamespacePrefix "battery" ; vann:preferredNamespaceUri "https://w3id.org/emmo/domain/battery" ; - owl:backwardCompatibleWith "0.12.0-beta" ; - owl:priorVersion "0.12.0-beta" ; - owl:versionInfo "0.12.1-beta" ; + owl:backwardCompatibleWith "0.12.1beta" ; + owl:priorVersion "0.12.1beta" ; + owl:versionInfo "0.13.0-beta" ; foaf:logo "https://raw.githubusercontent.com/emmo-repo/domain-battery/master/docs/assets/img/fig/png/domain-battery-logo.png" . ################################################################# diff --git a/catalog-v001.xml b/catalog-v001.xml index f50b0d5..f130e6a 100644 --- a/catalog-v001.xml +++ b/catalog-v001.xml @@ -1,14 +1,14 @@ - - + + - - - + + + - + diff --git a/docs/scripts/ttl_to_rst.py b/docs/scripts/ttl_to_rst.py index b0e7d38..6d93548 100644 --- a/docs/scripts/ttl_to_rst.py +++ b/docs/scripts/ttl_to_rst.py @@ -1,4 +1,5 @@ from rdflib import Graph +import os @@ -83,6 +84,10 @@ def entities_to_rst(entities: list[dict]) -> str: rst = "" for item in entities: + # Check if '#' is in the IRI + if '#' not in item['IRI']: + print(f"Skipping IRI without '#': {item['IRI']}") + continue # Skip this entity if no hash is present iri_prefix, iri_suffix = item['IRI'].split("#") @@ -95,7 +100,7 @@ def entities_to_rst(entities: list[dict]) -> str: rst += "\n\n" rst += "* " + item['IRI'] + "\n\n" - + rst += ".. raw:: html\n\n" indent = " " rst += indent + "\n" @@ -107,12 +112,13 @@ def entities_to_rst(entities: list[dict]) -> str: rst += indent + "\n" if value.startswith("http"): value = f"""{value}""" - value = value.encode('ascii', 'xmlcharrefreplace') - value = value.decode('utf-8') - value = value.replace('\n', '\n' + indent) + else: + value = value.encode('ascii', 'xmlcharrefreplace') + value = value.decode('utf-8') + value = value.replace('\n', '\n' + indent) rst += indent + "\n" rst += indent + "\n" - + rst += indent + "
" + key + "" + value + "
\n" rst += "\n\n" @@ -130,38 +136,40 @@ def render_rst_bottom() -> str: ########### RUN THE RENDERING WORKFLOW ############## - def rendering_workflow(): - - # PAGES - ttl_modules = [ - {"section title": "Battery Concepts", - "path": "./battery.ttl"}, - {"section title": "Battery Quantities", - "path": "./batteryquantities.ttl"} - ] + # Adapt based on file structure + ttl_modules = [] + + # Check for old structure (root directory) + if os.path.isfile("./batteryquantities.ttl"): + ttl_modules.append({"section title": "Quantities used in Batteries", "path": "./batteryquantities.ttl"}) + elif os.path.isfile("./modules/quantities.ttl"): + ttl_modules.append({"section title": "Quantities used in Batteries", "path": "./modules/quantities.ttl"}) + else: + raise FileNotFoundError("No suitable TTL file found for battery quantities.") + + # Check for the battery file in the correct directory + if os.path.isfile("./battery.ttl"): + ttl_modules.append({"section title": "Battery Concepts", "path": "./battery.ttl"}) + else: + raise FileNotFoundError("No suitable TTL file found for battery concepts.") # GENERATE PAGES rst_filename = "battery.rst" - rst = render_rst_top() for module in ttl_modules: - g = load_ttl_from_url(module["path"]) - entities_list = extract_terms_info_sparql(g) page_title = module["section title"] rst += page_title + "\n" - for ind in range(len(page_title)): - rst += "=" - rst += "\n\n" + rst += "=" * len(page_title) + "\n\n" rst += entities_to_rst(entities_list) rst += render_rst_bottom() - with open("./docs/"+ rst_filename, "w+", encoding="utf-8") as f: + with open("./docs/" + rst_filename, "w+", encoding="utf-8") as f: f.write(rst) diff --git a/modules/catalog-v001.xml b/modules/catalog-v001.xml new file mode 100644 index 0000000..84f8ece --- /dev/null +++ b/modules/catalog-v001.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/battery-products.ttl b/modules/products.ttl similarity index 100% rename from battery-products.ttl rename to modules/products.ttl diff --git a/batteryquantities.ttl b/modules/quantities.ttl similarity index 98% rename from batteryquantities.ttl rename to modules/quantities.ttl index 33206d3..2f0ec9b 100644 --- a/batteryquantities.ttl +++ b/modules/quantities.ttl @@ -12,8 +12,8 @@ @base . rdf:type owl:Ontology ; - owl:versionIRI ; - owl:imports ; + owl:versionIRI ; + owl:imports ; dcterms:abstract "This battery quantities ontology is a domain of the Elementary Multiperspective Materials Ontology (EMMO). It is a specialized framework designed to represent and organize knowledge about battery quantities. It is designed to integrate with the battery domain ontology or other ontologies from the EMMO ecosystem. The main focus of this ontology is to provide machine-readable descriptions of common battery quantities, linking both to the larger descriptions of physical quantities in EMMO as well as other sources of information like the IEC, QUDT, Wikidata, etc. It should be used to support linked data generation in the battery domain."@en ; dcterms:contributor "Casper Welzel Andersen" , "Francesca Lonstad Bleken" , @@ -21,7 +21,7 @@ dcterms:creator "Eibar Flores" , "Simon Clark" ; dcterms:license "https://creativecommons.org/licenses/by/4.0/legalcode" ; - owl:versionInfo "0.12.1-beta" . + owl:versionInfo "0.13.0-beta" . ################################################################# # Classes