Skip to content

Commit

Permalink
Merge pull request #1319 from OpenEnergyPlatform/feature-1020-export-…
Browse files Browse the repository at this point in the history
…of-existing-terms-and-definitions

Export of existing terms and definitions #1020
  • Loading branch information
areleu authored Dec 19, 2022
2 parents 9c808f6 + 8f81f7c commit 15a8b13
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .github/workflows/PostReleaseScripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Post Release Scripts
# on:
# workflow_dispatch: {}
# push:
# branches:
# - 'feature-1020-export-of-existing-terms-and-definitions'
# First we test the setup, to see if the files are building correctly once that is checked we introduce the wiki upload each release.
on:
push:
tags:
- "v*"
branches:
- 'feature-1020-export-of-existing-terms-and-definitions'
jobs:
exportTermsDefinitions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.7'
architecture: x64
- uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
- name: install python dependencies
run: pip install -r src/scripts/requirements.txt
- name: setup robot
run: |
wget https://github.com/ontodev/robot/releases/download/v1.9.0/robot.jar -O src/robot.jar
- name: Build ETD xlsx
run: |
java -jar src/robot.jar merge --input "src/ontology/oeo.omn" \
--input "src/ontology/edits/oeo-model.omn" \
--input "src/ontology/edits/oeo-physical.omn" \
--input "src/ontology/edits/oeo-shared.omn" \
--input "src/ontology/edits/oeo-social.omn" \
--include-annotations true \
export --header "ID|LABEL|definition" \
--prefix "OEO: http://openenergy-platform.org/ontology/oeo/OEO_" \
--sort "LABEL" \
--export "src/scripts/etd/etd.xlsx"
- name: Build ETD md
run: |
python src/scripts/etd/etd.py
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: existing-terms-and-definitions
path: src/scripts/etd/glossary
# - name: Checkout wiki
# uses: actions/checkout@v2
# with:
# repository: ${{github.repository}}.wiki
# path: wiki
# - name: Push list to wiki
# run: |
# cd wiki
# cp -a ../src/scripts/etd/glossary/. .
# git config --local user.email "[email protected]"
# git config --local user.name "GitHub Action"
# git add .
# git diff-index --quiet HEAD || git commit -m "Add changes" && git push
2 changes: 1 addition & 1 deletion src/ontology/edits/oeo-physical.omn
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ pull request: https://github.com/OpenEnergyPlatform/ontology/pull/1135",
OEO_00010032


Class: <http://opennergy-plattform.org/ontology/oeo/OEO_00290002>
Class: <http://openenergy-platform.org/ontology/oeo/oeo-physical/OEO_00290002>

Annotations:
<http://purl.obolibrary.org/obo/IAO_0000115> "A surface azimuth angle is a quantity value with a plane angle unit that measures the deviation of the projection on a horizontal plane of the normal to the plane from the local meridian, with zero due south, east negative, and west positive."@en,
Expand Down
7 changes: 7 additions & 0 deletions src/scripts/etd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This script generates a glossary for existing terms and definitions formatted in a table in a markdown file.
The markdown file will be created in the same path (/ontology/src/scripts/etd/).

Guide:

1. Make sure you installed python3 and the python module pandas
2. Call the bash script etd.sh in the directory: ontology/src/scripts/etd
58 changes: 58 additions & 0 deletions src/scripts/etd/etd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import pandas as pd
import warnings
import re
import string
import pathlib
warnings.filterwarnings("ignore")
import sys

GLOSSARY_HEADER = """# Existing Terms and Definitions
"""
BASE_LINK_WIKI = "https://github.com/OpenEnergyPlatform/ontology/wiki/"
BASE_IRI = "http://openenergy-platform.org/ontology/oeo/"

if __name__ == '__main__':
arguments = sys.argv[1:]
if len(arguments) > 0:
target_path = arguments[0]
else:
target_path = 'src/scripts/etd'
cwd = os.getcwd()
df = pd.read_excel(pathlib.Path(target_path).joinpath("etd.xlsx").as_posix())

df = df.replace('\n', '<br>', regex=True)
df = df.sort_values("LABEL", key=lambda col: col.str.strip().str.lower())
# Create one table per letter:

pathlib.Path(cwd + "/src/scripts/etd/glossary/").mkdir(parents=True, exist_ok=True)

# header = GLOSSARY_HEADER + " ".join([f"[{letter}]({BASE_LINK_WIKI}{letter})" for letter in string.ascii_uppercase]) + "\n"

# with open(cwd + "/src/scripts/etd/glossary/glossary.md", "w") as fil:
# fil.write(header)
output = GLOSSARY_HEADER + "\n"
for letter in string.ascii_lowercase:
current_df = df[df["LABEL"].str.lower().str.startswith(letter)]
if current_df.empty:
continue
buffer = current_df.to_markdown(index=False)
buffer = re.sub(r"(?s)(http:\/\/openenergy-platform.org\/ontology\/oeo\/?)\w+-\w+\/(\w+)(?=_)_(\d+?)(?=\s)", r"\2:\3", buffer)
# There is a weird typo in surface azimuth angle ?
buffer = re.sub(r"(?s)(http:\/\/opennergy-plattform.org\/ontology\/oeo\/?)\/(\w+)(?=_)_(\d+?)(?=\s)", r"\2:\3", buffer)
# Remove the thing above when the typo is fixed
buffer =re.sub(r"(?s)(\w+?)(?=:):(\d+?)(?=\s)", r"[\1:\2]({}".format(BASE_IRI)+ r"\1_\2)", buffer)
title = f"## {letter.capitalize()}\n\n"
table = title + buffer + "\n\n"
#df.to_markdown(buf=cwd + "/src/scripts/etd/ETD.md", index=False)
output += table
with open(pathlib.Path(target_path).joinpath("glossary/glossary.md").as_posix(), "w") as fil:
fil.write(output)

# create csv output
df_csv = df.copy()
df_csv["ID"] = df_csv["ID"].str.replace("http://openenergy-platform.org/ontology/oeo/oeo-physical/", "")
df_csv["ID"] = df_csv["ID"].str.replace("http://openenergy-platform.org/ontology/oeo/oeo-model/", "")
df_csv["ID"] = df_csv["ID"].str.replace(":", "_")
df_csv.to_csv(pathlib.Path(target_path).joinpath("glossary/glossary.csv").as_posix(), index=False)
19 changes: 19 additions & 0 deletions src/scripts/etd/etd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
if [ -e ETD.md ]
then
rm ETD.md
fi
SCRIPT_PATH="$PWD"
ONTO_PATH="$(dirname "$(dirname "$SCRIPT_PATH")")""/ontology/"
robot merge --input "$ONTO_PATH""oeo.omn" \
--input "$ONTO_PATH""edits/oeo-model.omn" \
--input "$ONTO_PATH""edits/oeo-physical.omn" \
--input "$ONTO_PATH""edits/oeo-shared.omn" \
--input "$ONTO_PATH""edits/oeo-social.omn" \
--include-annotations true \
export --header "LABEL|ID|definition" \
--prefix "OEO: http://openenergy-platform.org/ontology/oeo/OEO_" \
--sort "LABEL" \
--export "$ETD_PATH""etd.xlsx"
python3 etd.py
rm etd.xlsx
3 changes: 3 additions & 0 deletions src/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pandas
tabulate
openpyxl

0 comments on commit 15a8b13

Please sign in to comment.