Skip to content

Commit b388b3e

Browse files
committed
minor updates
1 parent 36ab82e commit b388b3e

5 files changed

Lines changed: 29 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
This project provides a schema conversion platform that supports converting between various data modeling formats (like JSON Schema, LinkML, XSD, DTD, RDF, etc.) using a software architecture that supports different programming languages due to subprocess calling. It consists of:
44

55
* 🐍 A central **Flask Orchestrator** (main API + smart pathfinding + schema feature matching + converters in Python)
6-
*A **Java** converters
7-
* 🪦 A **Node.js TypeScript** converters
6+
***Java** converters
7+
* 🪦 **Node.js TypeScript** converters
88

99

1010
## Features

schema-conversion-orchestrator/app.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
from conversion_strategies import convert_with_strategy_most_features_preserved, ConversionStrategy, \
22
convert_with_strategy_least_character_loss
3-
from converter import (Converter, ConverterExternal)
4-
from schema_types import schema_language_from_string, SchemaLanguagesFeatures
3+
from converter import (Converter, ConverterExternal, prepare_conversion_results_for_serializing)
4+
from schema_types import schema_language_from_string
55
from logic import build_conversion_graph, find_paths
66
from register_converters import register_converters
77
from flask import Flask, request
88
from typing import List, Dict
9-
from schema_languages_loader import load_schema_language_features
9+
import json
1010

1111
app = Flask(__name__)
1212

13-
DETAILED_ERROR_OUTPUT = False
1413
CONVERSION_STRATEGY = ConversionStrategy.LeastCharacterLoss
1514

1615
converters: List[Converter] = register_converters()
1716
conversion_graph: Dict[str, List[Converter]] = build_conversion_graph(converters)
18-
schema_languages_features: SchemaLanguagesFeatures = load_schema_language_features()
17+
# schema_languages_features: SchemaLanguagesFeatures = load_schema_language_features()
1918

2019
print("Started Schema Conversion Orchestrator with the following converters:")
2120
for conv in converters:
@@ -52,12 +51,14 @@ def convert():
5251
target = data["targetFormat"]
5352
schema = data["schema"]
5453

55-
source = schema_language_from_string(source)
56-
target = schema_language_from_string(target)
54+
try:
55+
source = schema_language_from_string(source)
56+
target = schema_language_from_string(target)
57+
except ValueError as e:
58+
return {"error": str(e)}, 400
5759

5860
# if schema is an object, convert it to string
5961
if isinstance(schema, dict):
60-
import json
6162
schema = json.dumps(schema)
6263

6364
all_paths = find_paths(source, target, conversion_graph)
@@ -78,7 +79,7 @@ def convert():
7879

7980
if not success:
8081
# return error message of all attempts together with the attempt number (1 to n)
81-
return {"error": "All conversion paths failed.", attempts: attempts}, 500
82+
return {"error": "All conversion paths failed.", "attempts": prepare_conversion_results_for_serializing(attempts)}, 500
8283

8384
return {"schema": schema}, 200
8485

schema-conversion-orchestrator/conversion_strategies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from converter import (ConversionResult, ConversionResults, ConversionPaths, Converter, conversion_path_to_string, ConversionsCache)
66
from schema_types import SchemaLanguage
77
from logic import identify_schema_features, rank_paths
8-
from app import DETAILED_ERROR_OUTPUT
8+
9+
DETAILED_ERROR_OUTPUT = False
910

1011

1112
class ConversionStrategy(StrEnum):

schema-conversion-orchestrator/converter.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,15 @@ def convert(self, schema: str) -> str:
182182

183183
def conversion_path_to_string(path: ConversionPath) -> str:
184184
return " -> ".join([f"{conv.source_format.value} to {conv.target_format.value} via {conv.service_name}" for conv in path])
185+
186+
187+
def prepare_conversion_results_for_serializing(results: ConversionResults) -> dict:
188+
serialized_results = {}
189+
for idx, (success, schema_or_error, path) in enumerate(results):
190+
path_str = conversion_path_to_string(path)
191+
serialized_results[f"Attempt {idx + 1}"] = {
192+
"success": success,
193+
"schema_or_error": schema_or_error,
194+
"conversion_path": path_str
195+
}
196+
return serialized_results

test/send_test_request.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
# --- Configuration ---
66
SERVER_URL = "http://localhost:5002/convert"
7-
SOURCE_FORMAT = "Shacl"
8-
TARGET_FORMAT = "JsonSchema"
9-
SCHEMA_FILE = Path("schemas/owl.ttl")
7+
SOURCE_FORMAT = "JsonSchema"
8+
TARGET_FORMAT = "SHACL"
9+
SCHEMA_FILE = Path("schemas/preciceAdapterConfigSchema.schema.json")
1010

1111

1212
def main():

0 commit comments

Comments
 (0)