Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SOIL Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WZL-IQS-Public
Sensor Interfacing Language (SOIL)
SOIL Backend
Commits
93a99ef0
Commit
93a99ef0
authored
7 months ago
by
André Fugmann
Browse files
Options
Downloads
Patches
Plain Diff
Add semantic definitions to the translation process
parent
7cf0d1e1
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main.py
+1
-0
1 addition, 0 deletions
src/main.py
src/translate.py
+16
-2
16 additions, 2 deletions
src/translate.py
with
17 additions
and
2 deletions
src/main.py
+
1
−
0
View file @
93a99ef0
...
@@ -88,6 +88,7 @@ async def validate(model: str, files: list[UploadFile], semantic: bool = False):
...
@@ -88,6 +88,7 @@ async def validate(model: str, files: list[UploadFile], semantic: bool = False):
if
files
[
0
].
filename
.
endswith
(
'
json
'
):
if
files
[
0
].
filename
.
endswith
(
'
json
'
):
json_files
=
{
file
.
filename
[:
-
5
]:
json
.
loads
((
await
file
.
read
()).
decode
(
'
utf-8
'
))
for
file
in
files
}
json_files
=
{
file
.
filename
[:
-
5
]:
json
.
loads
((
await
file
.
read
()).
decode
(
'
utf-8
'
))
for
file
in
files
}
translated_files
=
translate
.
translate_files_to_text
(
json_files
)
translated_files
=
translate
.
translate_files_to_text
(
json_files
)
# TODO: Mapping
for
filename
in
translated_files
:
for
filename
in
translated_files
:
with
open
(
os
.
path
.
join
(
in_path
,
f
'
{
filename
}
.soil
'
),
'
wb
'
)
as
outfile
:
with
open
(
os
.
path
.
join
(
in_path
,
f
'
{
filename
}
.soil
'
),
'
wb
'
)
as
outfile
:
outfile
.
write
(
translated_files
[
filename
].
encode
(
'
utf-8
'
))
outfile
.
write
(
translated_files
[
filename
].
encode
(
'
utf-8
'
))
...
...
This diff is collapsed.
Click to expand it.
src/translate.py
+
16
−
2
View file @
93a99ef0
...
@@ -80,7 +80,14 @@ def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any
...
@@ -80,7 +80,14 @@ def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any
custom_descriptions
=
{}
custom_descriptions
=
{}
temp_output
=
element
[
"
elementType
"
]
+
"
"
+
element
[
"
name
"
].
replace
(
"
"
,
""
)
+
"
"
temp_output
=
element
[
"
elementType
"
]
+
"
"
+
element
[
"
name
"
].
replace
(
"
"
,
""
)
+
"
"
if
element
[
'
elementType
'
]
==
'
component
'
and
'
baseComponent
'
in
element
:
if
element
[
'
elementType
'
]
==
'
component
'
and
'
baseComponent
'
in
element
:
temp_output
+=
"
extends
"
+
get_element_type_name
(
element
[
"
baseComponent
"
],
filename
,
files
)
+
"
"
temp_output
+=
"
extends
"
+
element
[
'
baseComponent
'
][
'
name
'
]
+
"
"
if
(
element
[
"
elementType
"
]
==
"
component
"
or
element
[
"
elementType
"
]
==
"
function
"
or
element
[
"
elementType
"
]
==
"
variable
"
):
if
element
[
'
semanticDefinition
'
]
is
not
None
:
temp_output
+=
f
"
defines <
{
element
[
'
semanticDefinition
'
]
}
>
"
temp_output
+=
"
{
\n
"
temp_output
+=
"
{
\n
"
if
element
[
"
elementType
"
]
==
"
interface
"
:
if
element
[
"
elementType
"
]
==
"
interface
"
:
...
@@ -94,7 +101,7 @@ def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any
...
@@ -94,7 +101,7 @@ def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any
return
temp_output
+
"
}
\n\n
"
return
temp_output
+
"
}
\n\n
"
for
key
in
element
:
for
key
in
element
:
if
key
in
[
"
uuid
"
,
"
cardOpen
"
,
"
elementType
"
,
"
constant
"
]:
if
key
in
[
"
baseComponent
"
,
"
uuid
"
,
"
cardOpen
"
,
"
elementType
"
,
"
constant
"
,
"
semanticDefinition
"
]:
continue
continue
elif
key
in
[
"
arguments
"
,
"
returns
"
,
"
components
"
,
"
parameters
"
,
"
functions
"
,
"
measurements
"
]:
elif
key
in
[
"
arguments
"
,
"
returns
"
,
"
components
"
,
"
parameters
"
,
"
functions
"
,
"
measurements
"
]:
if
len
(
element
[
key
]):
if
len
(
element
[
key
]):
...
@@ -109,6 +116,13 @@ def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any
...
@@ -109,6 +116,13 @@ def element_to_text(element: Dict[str, any], filename: str, files: dict[str, any
elif
key
==
"
streams
"
:
elif
key
==
"
streams
"
:
if
len
(
element
[
key
])
>
0
:
if
len
(
element
[
key
])
>
0
:
temp_output
+=
"
streams:
\n
"
+
streams_to_text
(
element
[
key
])
temp_output
+=
"
streams:
\n
"
+
streams_to_text
(
element
[
key
])
elif
key
==
"
unit
"
:
# Probably too hacky to just check if the unit string contains ':'
# to determine if it is a semantic unit or not
if
'
:
'
in
element
[
'
unit
'
]:
temp_output
+=
f
"
unit: <
{
element
[
'
unit
'
]
}
>
\n
"
else
:
temp_output
+=
f
"
unit:
{
element
[
'
unit
'
]
}
\n
"
elif
key
==
"
range
"
:
elif
key
==
"
range
"
:
if
element
[
"
datatype
"
]
!=
"
enum
"
:
if
element
[
"
datatype
"
]
!=
"
enum
"
:
minimum
=
''
if
element
[
"
range
"
][
0
]
is
None
else
str
(
element
[
"
range
"
][
0
])
minimum
=
''
if
element
[
"
range
"
][
0
]
is
None
else
str
(
element
[
"
range
"
][
0
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment