From f50efb07d5b3048f6ed7c87dd2964fe0327eec37 Mon Sep 17 00:00:00 2001 From: kchason Date: Fri, 2 Jun 2023 11:41:14 -0400 Subject: [PATCH 1/9] CASE validate and dotnet build jobs --- .github/workflows/build.yml | 32 +++++++++++++++++++++++++++++ .github/workflows/case_validate.yml | 22 ++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/case_validate.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..2dbdef8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,32 @@ +name: CASE Validate + +on: [ push ] + +# Build all of the projects and run them against the CASE graph + +jobs: + dotnet: + runs-on: ubuntu-latest + steps: + + # Get the code from the repository to be packaged + - name: Get Repo + uses: actions/checkout@v3 + + # Install the .NET SDK + - name: Setup .NET + uses: actions/setup-dotnet@v3.2.0 + with: + dotnet-version: 6.x + + # Build the project + - name: Build + run: dotnet build + working-directory: ./dotnet/ + + # Run the built CASE conversion example + - name: Run CASE Conversion + run: | + dotnet run ../data/geo.json ../output/dotnet.geojson + cat ../output/dotnet.geojson + working-directory: ./dotnet/ diff --git a/.github/workflows/case_validate.yml b/.github/workflows/case_validate.yml new file mode 100644 index 0000000..338ae16 --- /dev/null +++ b/.github/workflows/case_validate.yml @@ -0,0 +1,22 @@ +name: CASE Validate + +on: [ push ] + +# Ensure all of the files in /data/ are valid CASE graphs. + +jobs: + validate: + runs-on: ubuntu-latest + steps: + + # Get the code from the repository to be packaged + - name: Get Repo + uses: actions/checkout@v3 + + # Validate the CASE graphs in the /data/ directory + - name: CASE Validate + uses: kchason/case-validation-action@v2.6.1 + with: + case-path: "./data/" + case-version: "case-1.2.0" + extension-filter: "jsonld" From 79bea4b07fafe6947888ee9fe2e491d6496e4b8b Mon Sep 17 00:00:00 2001 From: kchason Date: Fri, 2 Jun 2023 11:42:11 -0400 Subject: [PATCH 2/9] Fix extension for CASE filter --- .github/workflows/case_validate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/case_validate.yml b/.github/workflows/case_validate.yml index 338ae16..21486ea 100644 --- a/.github/workflows/case_validate.yml +++ b/.github/workflows/case_validate.yml @@ -19,4 +19,4 @@ jobs: with: case-path: "./data/" case-version: "case-1.2.0" - extension-filter: "jsonld" + extension-filter: "json" From 4cf175d370ed5b545c067ac6f37a12f3665e2c15 Mon Sep 17 00:00:00 2001 From: kchason Date: Fri, 2 Jun 2023 11:44:58 -0400 Subject: [PATCH 3/9] Add Python example --- .github/workflows/build.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2dbdef8..88a8e16 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - # Get the code from the repository to be packaged + # Get the code from the repository - name: Get Repo uses: actions/checkout@v3 @@ -30,3 +30,28 @@ jobs: dotnet run ../data/geo.json ../output/dotnet.geojson cat ../output/dotnet.geojson working-directory: ./dotnet/ + + python: + runs-on: ubuntu-latest + steps: + + # Get the code from the repository + - name: Get Repo + uses: actions/checkout@v3 + + # Install Python + - name: Setup Python + uses: actions/setup-python@v4.6.1 + with: + python-version: 3.9 + + # Install the rdflib dependency + - name: Install Dependencies + run: pip install rdflib + + # Run the Python CASE conversion example + - name: Run CASE Conversion + run: | + python3 CASE2GeoJSON.py ../data/geo.json ../output/python.geojson + cat ../output/python.geojson + working-directory: ./python/ From cd68d3405da0e69e97403c9066c9245dc3aa3511 Mon Sep 17 00:00:00 2001 From: kchason Date: Fri, 2 Jun 2023 11:50:55 -0400 Subject: [PATCH 4/9] Add Java to build pipeline --- .github/workflows/build.yml | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 88a8e16..ac0acb9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,11 +47,39 @@ jobs: # Install the rdflib dependency - name: Install Dependencies - run: pip install rdflib + run: pip3 install rdflib # Run the Python CASE conversion example - name: Run CASE Conversion run: | + ls python3 CASE2GeoJSON.py ../data/geo.json ../output/python.geojson cat ../output/python.geojson working-directory: ./python/ + + java: + runs-on: ubuntu-latest + steps: + + # Get the code from the repository + - name: Get Repo + uses: actions/checkout@v3 + + # Install Java + - name: Setup Java + uses: actions/setup-java@v3.11.0 + with: + java-version: '18' + cache: 'maven' + + # Build the project + - name: Build Project + run: mvn compile assembly:single + working-directory: ./java/ + + # Run the Java CASE conversion example + - name: Run CASE Conversion + run: | + java -jar ./target/case2geo-0.1.0.jar ../../data/geo.json ../../output/java.geojson + cat ../output/java.geojson + working-directory: ./java/ From 287185d909aaccc509b8db47e3cc8f84e5b563d2 Mon Sep 17 00:00:00 2001 From: kchason Date: Fri, 2 Jun 2023 11:54:00 -0400 Subject: [PATCH 5/9] Add required parameter, fix capitalization --- .github/workflows/build.yml | 1 + .pre-commit-config.yaml | 2 +- python/CASE2GeoJSON.py | 86 +++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 python/CASE2GeoJSON.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac0acb9..c463f68 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -69,6 +69,7 @@ jobs: - name: Setup Java uses: actions/setup-java@v3.11.0 with: + distribution: 'temurin' java-version: '18' cache: 'maven' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c5945e..55a1332 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files - - id: check-case-conflict + # - id: check-case-conflict - id: check-merge-conflict - id: check-json - id: check-xml diff --git a/python/CASE2GeoJSON.py b/python/CASE2GeoJSON.py new file mode 100644 index 0000000..62a3921 --- /dev/null +++ b/python/CASE2GeoJSON.py @@ -0,0 +1,86 @@ +import json +import sys +from os.path import exists, isdir, isfile + +from geotypes import GeoRecord +from geoutilities import records_to_geojson, remove_nulls +from rdflib import Graph + +# Parse the arguments from the CLI to get the input and output filenames +if len(sys.argv) != 3: + print("Usage: python case2geojson.py ") + sys.exit(1) + +input_filename: str = sys.argv[1] +output_filename: str = sys.argv[2] + +# Ensure the input file exists +if not exists(input_filename) and not isfile(input_filename): + print(f"File not found: {input_filename}") + sys.exit(1) + +# Ensure the output directory exists +output_directory: str = output_filename[: output_filename.rfind("/")] +if not exists(output_directory) and not isdir(output_directory): + print(f"Directory not found: {output_directory}") + sys.exit(1) + +# Build the rdflib graph from the input file +graph: Graph = Graph() +graph.parse(input_filename) + +# Write the SPARQL query to get the data from the graph +query: str = """ + SELECT ?lLatitude ?lLongitude ?lAddressType ?lCountry ?lLocality ?lPostalCode ?lRegion ?lStreet + WHERE + { + ?nLocation a uco-location:Location . + OPTIONAL + { + ?nLocation uco-core:hasFacet ?nLatLongFacet . + ?nLatLongFacet a uco-location:LatLongCoordinatesFacet . + OPTIONAL { ?nLatLongFacet uco-location:latitude ?lLatitude . } + OPTIONAL { ?nLatLongFacet uco-location:longitude ?lLongitude . } + } + + OPTIONAL { + ?nLocation uco-core:hasFacet ?nSimpleAddressFacet . + ?nSimpleAddressFacet a uco-location:SimpleAddressFacet . + OPTIONAL { ?nSimpleAddressFacet uco-location:addressType ?lAddressType . } + OPTIONAL { ?nSimpleAddressFacet uco-location:country ?lCountry . } + OPTIONAL { ?nSimpleAddressFacet uco-location:locality ?lLocality . } + OPTIONAL { ?nSimpleAddressFacet uco-location:postalCode ?lPostalCode . } + OPTIONAL { ?nSimpleAddressFacet uco-location:region ?lRegion . } + OPTIONAL { ?nSimpleAddressFacet uco-location:street ?lStreet . } + } + } + """ + +results = graph.query(query) + +# Define the list of GeoRecords +records: list[GeoRecord] = [] + +# Loop through the results and add them to the list of GeoRecords if the latitude and longitude are present +for row in results: + geo_record: GeoRecord = GeoRecord() + geo_record.Latitude = row.lLatitude + geo_record.Longitude = row.lLongitude + geo_record.AddressType = row.lAddressType + geo_record.Country = row.lCountry + geo_record.Locality = row.lLocality + geo_record.PostalCode = row.lPostalCode + geo_record.Region = row.lRegion + geo_record.Street = row.lStreet + records.append(geo_record) + +# Convert the data to a GeoJSON structured object +geoJSON = records_to_geojson(records) + +# Remove null values from the GeoJSON object +geoDict: dict = geoJSON.reprJSON() +geoDict = remove_nulls(geoDict) + +# Write the GeoJSON object to the output file +with open(output_filename, "w") as output_file: + output_file.write(json.dumps(geoDict, indent=4)) From 1f58a915582bcba54201d43e4c5cebbe6c243065 Mon Sep 17 00:00:00 2001 From: kchason Date: Fri, 2 Jun 2023 11:54:17 -0400 Subject: [PATCH 6/9] Re-add job --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 55a1332..3c5945e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files - # - id: check-case-conflict + - id: check-case-conflict - id: check-merge-conflict - id: check-json - id: check-xml From 334d3baa3c468c634fe973d23b7e06008bc5eedd Mon Sep 17 00:00:00 2001 From: kchason Date: Fri, 2 Jun 2023 12:45:09 -0400 Subject: [PATCH 7/9] Add pre-commit --- .github/workflows/build.yml | 6 +++--- .github/workflows/lint.yml | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c463f68..584f943 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: CASE Validate +name: Build Jobs on: [ push ] @@ -76,11 +76,11 @@ jobs: # Build the project - name: Build Project run: mvn compile assembly:single - working-directory: ./java/ + working-directory: ./java/case2geo/ # Run the Java CASE conversion example - name: Run CASE Conversion run: | java -jar ./target/case2geo-0.1.0.jar ../../data/geo.json ../../output/java.geojson cat ../output/java.geojson - working-directory: ./java/ + working-directory: ./java/case2geo/ diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..9f7f0d3 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,20 @@ +name: Lint + +on: [ push ] + +# Build all of the projects and run them against the CASE graph + +jobs: + lint: + runs-on: ubuntu-latest + steps: + + # Get the code from the repository + - name: Get Repo + uses: actions/checkout@v3 + + # Install pre-commit and run it + - name: Pre-commit Checks + run: | + pip -q install pre-commit + pre-commit run --all-files From 8e1c97096754a5d994acdaf415c43448439b8c41 Mon Sep 17 00:00:00 2001 From: kchason Date: Fri, 2 Jun 2023 12:51:15 -0400 Subject: [PATCH 8/9] Switch version reference --- .pre-commit-config.yaml | 1 - java/case2geo/pom.xml | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c5945e..c1b554e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,6 @@ repos: - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files - - id: check-case-conflict - id: check-merge-conflict - id: check-json - id: check-xml diff --git a/java/case2geo/pom.xml b/java/case2geo/pom.xml index 9795deb..e08df6c 100644 --- a/java/case2geo/pom.xml +++ b/java/case2geo/pom.xml @@ -15,8 +15,8 @@ UTF-8 - 1.18 - 1.18 + 18 + 18 org.caseontology.examples.CASE2Geo From d514e3da3abecc96cef7604788e62d9d609392b2 Mon Sep 17 00:00:00 2001 From: kchason Date: Fri, 2 Jun 2023 12:54:46 -0400 Subject: [PATCH 9/9] Fix output path --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 584f943..9cb7203 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -82,5 +82,5 @@ jobs: - name: Run CASE Conversion run: | java -jar ./target/case2geo-0.1.0.jar ../../data/geo.json ../../output/java.geojson - cat ../output/java.geojson + cat ../../output/java.geojson working-directory: ./java/case2geo/