-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add PycramRoboKudoPrinter for planning
- Loading branch information
1 parent
1268aad
commit c0c6024
Showing
4 changed files
with
70 additions
and
5 deletions.
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 |
---|---|---|
|
@@ -31,4 +31,8 @@ out/ | |
|
||
# owl2anything | ||
owl2anything/output/* | ||
*.owl | ||
*.owl | ||
|
||
### Emacs ### | ||
# emacs backup files | ||
*~ |
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
53 changes: 53 additions & 0 deletions
53
src/main/java/com/malte3d/suturo/knowledge/owl2anything/output/PyCramRoboKudoPrinter.java
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,53 @@ | ||
package com.malte3d.suturo.knowledge.owl2anything.output; | ||
|
||
import com.google.gson.Gson; | ||
import com.malte3d.suturo.knowledge.owl2anything.converter.OwlRecord; | ||
import lombok.NonNull; | ||
import lombok.experimental.UtilityClass; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.TreeMap; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Utility class to create a .py file for the RoboKudo - PyCRAM - KnowRob interface | ||
*/ | ||
@Slf4j | ||
@UtilityClass | ||
public class PyCramRoboKudoPrinter { | ||
|
||
private static final Gson GSON = new Gson().newBuilder() | ||
.enableComplexMapKeySerialization() | ||
.disableHtmlEscaping() | ||
.setPrettyPrinting() | ||
.create(); | ||
|
||
public static void print(@NonNull List<OwlRecord> classes, @NonNull File outputFile) { | ||
|
||
List<OwlRecord> output = PerceptionClassesFilter.filter(classes); | ||
|
||
TreeMap<String, String> perceptionNames = output.stream() | ||
.collect(Collectors.toMap(OwlRecordConverter::toRoboKudoFormat, OwlRecordConverter::toKnowRobFormat, | ||
(c1, c2) -> { | ||
throw new IllegalStateException(String.format("Duplicate robokudo name for classes %s and %s", c1, c2)); | ||
}, | ||
TreeMap::new)); | ||
|
||
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)) { | ||
|
||
writer.append("mapping = ").append(GSON.toJson(perceptionNames)); | ||
|
||
log.info("Successfully created {}", outputFile.getName()); | ||
|
||
} catch (IOException e) { | ||
log.error("Error while writing the Cram Object Names file", e); | ||
} | ||
} | ||
} |