-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1319 from OpenEnergyPlatform/feature-1020-export-…
…of-existing-terms-and-definitions Export of existing terms and definitions #1020
- Loading branch information
Showing
6 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pandas | ||
tabulate | ||
openpyxl |