Skip to content

Commit 9417c42

Browse files
committed
now always return all results
1 parent a2b6d4c commit 9417c42

16 files changed

Lines changed: 357 additions & 98 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE NEWSPAPER [
2+
3+
<!ELEMENT NEWSPAPER (ARTICLE+)>
4+
<!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)>
5+
<!ELEMENT HEADLINE (#PCDATA)>
6+
<!ELEMENT BYLINE (#PCDATA)>
7+
<!ELEMENT LEAD (#PCDATA)>
8+
<!ELEMENT BODY (#PCDATA)>
9+
<!ELEMENT NOTES (#PCDATA)>
10+
11+
<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
12+
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
13+
<!ATTLIST ARTICLE DATE CDATA #IMPLIED>
14+
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
15+
16+
<!ENTITY NEWSPAPER "Vervet Logic Times">
17+
<!ENTITY PUBLISHER "Vervet Logic Press">
18+
<!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">
19+
20+
]>
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
{
2+
"$defs": {
3+
"interface": {
4+
"if": {
5+
"properties": {
6+
"is_received": {
7+
"const": true
8+
}
9+
}
10+
},
11+
"properties": {
12+
"is_received": {
13+
"description": "Whether mesh is received from another participant for (direct) API access or not (i.e. provided).",
14+
"type": "boolean"
15+
},
16+
"location": {
17+
"description": "Further specification of mesh locations",
18+
"examples": [
19+
"faceCenters",
20+
"volumeCenters",
21+
"faceNodes",
22+
"nodes"
23+
],
24+
"minLength": 1,
25+
"type": "string"
26+
},
27+
"mesh_name": {
28+
"default": "Fluid-Mesh",
29+
"description": "Name of the mesh associated with this interface.",
30+
"examples": [
31+
"Fluid-Mesh",
32+
"Solid-Mesh",
33+
"Fluid-Upstream-Mesh",
34+
"Fluid-Upstream-Mesh-Centers",
35+
"Fluid-Upstream-Mesh-Nodes"
36+
],
37+
"minLength": 6,
38+
"pattern": "^[A-Z][a-zA-Z0-9]*(?:-[A-Z][a-zA-Z0-9]*)*-Mesh(?:-[A-Z][a-zA-Z0-9]*)*$",
39+
"type": "string"
40+
},
41+
"patches": {
42+
"description": "List of mesh or geometry patches (boundary or volume) to locate the interface.",
43+
"items": {
44+
"minLength": 1,
45+
"type": "string"
46+
},
47+
"minItems": 1,
48+
"type": "array"
49+
},
50+
"read_data": {
51+
"description": "List of data fields to be read from this mesh.",
52+
"items": {
53+
"$ref": "#/$defs/precice_data"
54+
},
55+
"type": "array"
56+
},
57+
"write_data": {
58+
"description": "List of data fields to be written to this mesh.",
59+
"items": {
60+
"$ref": "#/$defs/precice_data"
61+
},
62+
"type": "array"
63+
}
64+
},
65+
"required": [
66+
"mesh_name"
67+
],
68+
"then": {
69+
"not": {
70+
"required": [
71+
"location"
72+
]
73+
}
74+
},
75+
"type": "object"
76+
},
77+
"precice_data": {
78+
"properties": {
79+
"name": {
80+
"default": "Force",
81+
"description": "Name of the data as specified in the preCICE configuration.",
82+
"examples": [
83+
"Force",
84+
"Displacement",
85+
"Velocity",
86+
"Temperature",
87+
"Heat-Flux",
88+
"Force1",
89+
"Force-Left",
90+
"Heat-Transfer-Coefficient",
91+
"Sink-Temperature"
92+
],
93+
"minLength": 1,
94+
"pattern": "^[A-Z][a-zA-Z0-9]*(?:-[A-Za-z0-9]+)*$",
95+
"type": "string"
96+
},
97+
"operation": {
98+
"description": "Operation applied by the adapter on the data (optional).",
99+
"examples": [
100+
"value",
101+
"gradient"
102+
],
103+
"minLength": 1,
104+
"type": "string"
105+
},
106+
"solver_name": {
107+
"description": "Name of the data as used by the solver (optional).",
108+
"examples": [
109+
"temp",
110+
"T"
111+
],
112+
"minLength": 1,
113+
"type": "string"
114+
}
115+
},
116+
"required": [
117+
"name"
118+
],
119+
"type": "object"
120+
}
121+
},
122+
"$schema": "http://json-schema.org/draft-07/schema#",
123+
"additionalProperties": {
124+
"additionalProperties": {
125+
"oneOf": [
126+
{
127+
"description": "An optional string setting, such as the location of the solver configuration file.",
128+
"examples": [
129+
"root_path",
130+
"model_name",
131+
"input_file_path",
132+
"output_file_path"
133+
],
134+
"title": "String property",
135+
"type": "string"
136+
},
137+
{
138+
"description": "An optional number setting, such as the write interval of the solver.",
139+
"examples": [
140+
"write-interval",
141+
"delay"
142+
],
143+
"title": "Number property",
144+
"type": "number"
145+
}
146+
],
147+
"title": "Solver parameter"
148+
},
149+
"description": "Optional solver specific settings. We recommend calling the main object after the solver, e.g. 'mbdyn'",
150+
"examples": [
151+
"mbdyn",
152+
"issm",
153+
"code_aster",
154+
"tau"
155+
],
156+
"title": "Solver settings",
157+
"type": "object"
158+
},
159+
"description": "A JSON schema for configurations of adapters and tools within the preCICE ecosystem. Use the schema for validation and LLM-based auto-conversion to other configuration languages (e.g., OpenFOAM dictionary or YAML). The schema is developed as part of the preECO standardization, see https://precice.discourse.group/t/shape-the-future-of-the-precice-ecosystem-the-preeco-project/2019.",
160+
"metaConfigurator": {
161+
"aiExportFormats": {
162+
"ISSM": {
163+
"description": "Export as an ISSM preCICE Adapter Configuration in YAML.",
164+
"url": "https://github.com/precice/preeco-orga/blob/main/adapter-config-schema/export-formats/issm-example.yaml"
165+
},
166+
"OpenFOAM": {
167+
"description": "Export as an OpenFOAM preCICE Adapter Configuration.",
168+
"url": "https://github.com/precice/tutorials/blob/develop/perpendicular-flap/fluid-openfoam/system/preciceDict"
169+
}
170+
}
171+
},
172+
"properties": {
173+
"interfaces": {
174+
"items": {
175+
"$ref": "#/$defs/interface"
176+
},
177+
"minItems": 1,
178+
"type": "array"
179+
},
180+
"participant_name": {
181+
"default": "Fluid",
182+
"description": "Name of the participant.",
183+
"examples": [
184+
"Fluid",
185+
"Solid",
186+
"Fluid-Left"
187+
],
188+
"minLength": 1,
189+
"pattern": "^[A-Z][a-zA-Z0-9-]*$",
190+
"type": "string"
191+
},
192+
"precice_config_file_path": {
193+
"default": "../precice-config.xml",
194+
"description": "Path to the preCICE configuration file relative to the current working directory of the coupled solver.",
195+
"minLength": 1,
196+
"pattern": "^/?(?:\\.\\./)*([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*/)*[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\\.xml$",
197+
"type": "string"
198+
}
199+
},
200+
"required": [
201+
"participant_name",
202+
"precice_config_file_path",
203+
"interfaces"
204+
],
205+
"title": "PreciseAdapterConfig",
206+
"type": "object"
207+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
2+
xmlns:tns="http://tempuri.org/PurchaseOrderSchema.xsd"
3+
targetNamespace="http://tempuri.org/PurchaseOrderSchema.xsd"
4+
elementFormDefault="qualified">
5+
<xsd:element name="PurchaseOrder" type="tns:PurchaseOrderType"/>
6+
<xsd:complexType name="PurchaseOrderType">
7+
<xsd:sequence>
8+
<xsd:element name="ShipTo" type="tns:USAddress" maxOccurs="2"/>
9+
<xsd:element name="BillTo" type="tns:USAddress"/>
10+
</xsd:sequence>
11+
<xsd:attribute name="OrderDate" type="xsd:date"/>
12+
</xsd:complexType>
13+
14+
<xsd:complexType name="USAddress">
15+
<xsd:sequence>
16+
<xsd:element name="name" type="xsd:string"/>
17+
<xsd:element name="street" type="xsd:string"/>
18+
<xsd:element name="city" type="xsd:string"/>
19+
<xsd:element name="state" type="xsd:string"/>
20+
<xsd:element name="zip" type="xsd:integer"/>
21+
</xsd:sequence>
22+
<xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/>
23+
</xsd:complexType>
24+
</xsd:schema>

schema-conversion-orchestrator/ConvertersLinkMl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def converter_logic(self, schema: str) -> str:
5151
SchemaLanguage.JsonLD: JSONLDGenerator,
5252
SchemaLanguage.SHACL: ShaclGenerator,
5353
SchemaLanguage.Owl: OwlSchemaGenerator,
54-
SchemaLanguage.Docs_LinkMl: DocGenerator,
55-
SchemaLanguage.PythonLinkMl: PythonGenerator,
54+
# SchemaLanguage.Docs_LinkMl: DocGenerator,
55+
# SchemaLanguage.PythonLinkMl: PythonGenerator,
5656
# SchemaLanguage.Java_LinkMl: JavaGenerator, # needs directory also as argument
5757
SchemaLanguage.Shex: ShExGenerator,
5858
SchemaLanguage.SqlAlchemy: SQLAlchemyGenerator

schema-conversion-orchestrator/ConvertersMdModels.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ def converter_logic(self, schema: str) -> str:
2323
return dm.convert_to(Templates.Protobuf)
2424
elif self.target_language == SchemaLanguage.Xsd:
2525
return dm.convert_to(Templates.XmlSchema)
26-
elif self.target_language == SchemaLanguage.PythonPydantic:
27-
return dm.convert_to(Templates.PythonPydantic)
26+
# elif self.target_language == SchemaLanguage.PythonPydantic:
27+
# return dm.convert_to(Templates.PythonPydantic)
2828
elif self.target_language == SchemaLanguage.JsonSchema:
2929
return dm.convert_to(Templates.JsonSchema) # test difference with JsonSchemaAll
3030
elif self.target_language == SchemaLanguage.GraphQL:
3131
return dm.convert_to(Templates.Graphql)
32-
elif self.target_language == SchemaLanguage.Julia_MdModels:
33-
return dm.convert_to(Templates.Julia)
32+
# elif self.target_language == SchemaLanguage.Julia_MdModels:
33+
# return dm.convert_to(Templates.Julia)
3434
elif self.target_language == SchemaLanguage.Mermaid:
3535
return dm.convert_to(Templates.Mermaid)
3636
elif self.target_language == SchemaLanguage.SHACL:
3737
return dm.convert_to(Templates.Shacl)
38-
elif self.target_language == SchemaLanguage.Rust_MdModels:
39-
return dm.convert_to(Templates.Rust)
40-
elif self.target_language == SchemaLanguage.TypeScript_MdModels:
41-
return dm.convert_to(Templates.Typescript)
38+
# elif self.target_language == SchemaLanguage.Rust_MdModels:
39+
# return dm.convert_to(Templates.Rust)
40+
# elif self.target_language == SchemaLanguage.TypeScript_MdModels:
41+
# return dm.convert_to(Templates.Typescript)
4242
elif self.target_language == SchemaLanguage.Shex:
4343
return dm.convert_to(Templates.Shex)
4444
else:

schema-conversion-orchestrator/app.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
from conversion_strategies import ConversionStrategy, \
2-
convert_with_strategy_least_character_loss
3-
from converter import (Converter, prepare_conversion_results_for_serializing)
1+
from ranking_strategies import RankingStrategy, \
2+
rank_with_strategy_least_character_loss
3+
from attempt_conversions import attempt_all_conversion_paths
4+
from converter import (Converter)
5+
from print_conversion_results import print_conversion_results
6+
from serialize_conversion_results import serialize_conversion_results
47
from schema_types import schema_language_from_string
58
from logic import build_conversion_graph, find_paths
69
from register_converters import register_converters
@@ -10,7 +13,7 @@
1013

1114
app = Flask(__name__)
1215

13-
CONVERSION_STRATEGY = ConversionStrategy.LeastCharacterLoss
16+
RANKING_STRATEGY = RankingStrategy.LeastCharacterLoss
1417

1518
converters: List[Converter] = register_converters()
1619
conversion_graph: Dict[str, List[Converter]] = build_conversion_graph(converters)
@@ -27,6 +30,10 @@ def health():
2730

2831
@app.route("/convert", methods=["POST"])
2932
def convert():
33+
"""
34+
REST POST Request to convert a schema from sourceLanguage to targetLanguage.
35+
:return: a JSON array as a list of all attempted paths and their results.
36+
"""
3037
data = request.json
3138
source = data["sourceLanguage"]
3239
target = data["targetLanguage"]
@@ -46,29 +53,16 @@ def convert():
4653
if not all_paths:
4754
return {"error": "No path found for conversion from source " + source + " to target " + target + "."}, 400
4855

49-
if CONVERSION_STRATEGY == ConversionStrategy.LeastCharacterLoss:
50-
attempts = convert_with_strategy_least_character_loss(
51-
source, target, schema, all_paths)
52-
else:
53-
return {"error": "Unknown conversion strategy: " + CONVERSION_STRATEGY}, 500
54-
55-
best_attempt = attempts[0]
56-
success, schema, conversion_path = best_attempt
57-
58-
if not success:
59-
# return error message of all attempts together with the attempt number (1 to n)
60-
return {"error": "All conversion paths failed.", "attempts": prepare_conversion_results_for_serializing(attempts)}, 500
56+
results = attempt_all_conversion_paths(source, target, schema, all_paths)
6157

62-
return {"schema": schema}, 200
58+
if RANKING_STRATEGY == RANKING_STRATEGY.LeastCharacterLoss:
59+
rank_with_strategy_least_character_loss(results)
60+
else:
61+
return {"error": "Unknown conversion strategy: " + RANKING_STRATEGY}, 500
6362

63+
print_conversion_results(results)
6464

65-
def call_internal_converter(source: str, target: str, schema: str) -> str:
66-
if source == "JsonSchema" and target == "LinkMl":
67-
return f"[Python] Converted from {source} to {target}: {schema}"
68-
elif source == "LinkMl" and target == "OntologyRdf":
69-
return f"[Python] Converted from {source} to {target}: {schema}"
70-
else:
71-
raise Exception("Unsupported internal conversion")
65+
return {"results": serialize_conversion_results(results)}, 200
7266

7367

7468
if __name__ == "__main__":

0 commit comments

Comments
 (0)