-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from discipl/filler
Added integration with flintfiller
- Loading branch information
Showing
25 changed files
with
7,927 additions
and
857 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
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,34 @@ | ||
name: Tests | ||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-16.04, macos-latest, windows-latest ] | ||
name: Run Tests | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- uses: actions/setup-java@v1 | ||
with: | ||
java-version: 11 | ||
- name: Test | ||
uses: GabrielBB/xvfb-action@v1 | ||
with: | ||
run: ./gradlew initProject test | ||
env: | ||
GRADLE_OPTS: -Dorg.gradle.daemon=false | ||
- name: Tests failed | ||
if: ${{ matrix.os == 'ubuntu-16.04' && failure() }} | ||
run: sudo apt-get install lynx && if [ -f ./code/build/reports/html/junit-noframes.html ]; then lynx -dump ./code/build/reports/html/junit-noframes.html; fi && if [ -f ./code/java/FlintParser/build/reports/tests/test/index.html ]; then lynx -dump ./code/java/FlintParser/build/reports/tests/test/index.html; fi && if [ -f ./code/java/FlintParser/build/reports/tests/test/classes/org.discipl.flint.flintfiller.FlintFillerTest.html ]; then lynx -dump ./code/java/FlintParser/build/reports/tests/test/classes/org.discipl.flint.flintfiller.FlintFillerTest.html; fi | ||
- name: Upload Test Results | ||
if: ${{ always() }} | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: test-results-${{ matrix.os }} | ||
path: code/java/FlintParser/build/reports/tests/test |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
code/java/FlintParser/src/main/kotlin/org/discipl/flint/flintfiller/FlintFiller.kt
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 org.discipl.flint.flintfiller | ||
|
||
import org.apache.commons.exec.CommandLine | ||
import org.apache.commons.exec.DefaultExecutor | ||
import org.apache.commons.exec.PumpStreamHandler | ||
import org.apache.commons.lang3.SystemUtils | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
|
||
|
||
class FlintFiller(private val pathToFillerDir: String, private val outputDir: String) { | ||
fun run(file: String, onCommandOutput: (String) -> Unit = {}): String { | ||
Files.createDirectories(Path.of(outputDir)) | ||
val command = "${pathToFillerDir}/${osSpecificFlintFiller()} ${fillerArgs(file, outputDir)}" | ||
val cmdLine: CommandLine = CommandLine.parse(command) | ||
|
||
val outputStream = StringOutputStream() | ||
val streamHandler = PumpStreamHandler(outputStream) | ||
|
||
val executor = DefaultExecutor() | ||
executor.streamHandler = streamHandler | ||
|
||
try { | ||
val exitCode = executor.execute(cmdLine) | ||
if (exitCode != 0) throw Exception("Bad exit code") | ||
onCommandOutput("command output:\n${outputStream.value()}") | ||
return Files.readString(Path.of(outputDir).resolve("flintFrame.json")) | ||
} catch (e: Exception) { | ||
throw Exception( | ||
"Something went wrong while running flint filler\ncommand output:\n${outputStream.value()}", | ||
e | ||
) | ||
} | ||
} | ||
|
||
private fun osSpecificFlintFiller(): String { | ||
return when { | ||
SystemUtils.IS_OS_WINDOWS -> "flintfiller-windows.exe" | ||
SystemUtils.IS_OS_LINUX -> "flintfiller-linux" | ||
SystemUtils.IS_OS_MAC_OSX -> "flintfiller-macos" | ||
else -> throw NotImplementedError("Os ${SystemUtils.OS_NAME} is not supported") | ||
} | ||
} | ||
|
||
private fun fillerArgs(inputFile: String, outputDir: String): String { | ||
val inputFileLine = "-x ${inputFile}" | ||
val dictFile = "-d ${outputDir}/dict.json" | ||
val dataFrameFile = "-df ${outputDir}/dataFrame.csv" | ||
val postTaggedDataFrameFile = "-pt ${outputDir}/postTaggedDataFrame_.csv" | ||
val flintFrame = "-fo ${outputDir}/flintFrame.json" | ||
return "$inputFileLine $dictFile $dataFrameFile $postTaggedDataFrameFile $flintFrame" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
code/java/FlintParser/src/main/kotlin/org/discipl/flint/flintfiller/StringOutputStream.kt
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,15 @@ | ||
package org.discipl.flint.flintfiller | ||
|
||
import java.io.OutputStream | ||
|
||
class StringOutputStream : OutputStream() { | ||
private val sb = StringBuilder() | ||
|
||
override fun write(x: Int) { | ||
sb.append(x.toChar()) | ||
} | ||
|
||
fun value(): String { | ||
return sb.toString() | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
code/java/FlintParser/src/test/kotlin/org/discipl/flint/flintfiller/FlintFillerTest.kt
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,21 @@ | ||
package org.discipl.flint.flintfiller | ||
|
||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.`is` | ||
import org.hamcrest.Matchers.notNullValue | ||
import org.junit.jupiter.api.Test | ||
import java.nio.file.Path | ||
|
||
internal class FlintFillerTest { | ||
private val filler: FlintFiller = FlintFiller( | ||
System.getenv("FLINT_FILLER_DIR"), | ||
System.getenv("FLINT_FILLER_OUTPUT_DIR") | ||
) | ||
|
||
@Test | ||
fun run() { | ||
val flintModel = filler.run(System.getenv("FLINT_FILLER_TEST_FILE")) | ||
println(flintModel.substring(0..400)) | ||
assertThat(flintModel, `is`(notNullValue())) | ||
} | ||
} |
Oops, something went wrong.