-
Notifications
You must be signed in to change notification settings - Fork 2
Add base functionality and tests #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c629566
Add base functionality and tests
Karolina-Bogacka dd60627
Simplify cod
Karolina-Bogacka 130ee75
Correct test error
Karolina-Bogacka 61f385b
Uncommit semanticdb files
Karolina-Bogacka 12fe5ed
Move to more meaningful part of gitignore
Karolina-Bogacka 2819d70
Move input file to remaining parameters to make it positional
Karolina-Bogacka d5554f6
Move to a stable version of jelly
Karolina-Bogacka 5fb4631
Check if lifecycle changes help
Karolina-Bogacka 66a7f52
Change jena versions
Karolina-Bogacka ae9a4cf
Revert "Change jena versions"
Karolina-Bogacka 0e27d8c
Fix AOT
Ostrzyciel c6d3d51
revert build.sbt change
Ostrzyciel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
38 changes: 31 additions & 7 deletions
38
src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfFromJelly.scala
This file contains hidden or 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 |
|---|---|---|
| @@ -1,16 +1,40 @@ | ||
| package eu.neverblink.jelly.cli.command.rdf | ||
| import caseapp.* | ||
| import eu.neverblink.jelly.cli.JellyCommand | ||
| import eu.ostrzyciel.jelly.convert.jena.riot.JellyLanguage | ||
| import org.apache.jena.riot.system.StreamRDFWriter | ||
| import org.apache.jena.riot.{RDFLanguages, RDFParser} | ||
|
|
||
| case class FromJellyRdfOptions() | ||
| import java.io.{ByteArrayInputStream, ByteArrayOutputStream, File, FileInputStream, InputStream} | ||
|
|
||
| case class RdfFromJellyOptions( | ||
| @ExtraName("input-file") inputFile: Option[String], | ||
Karolina-Bogacka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| object RdfFromJelly extends JellyCommand[RdfFromJellyOptions]: | ||
| override def group = "rdf" | ||
|
|
||
| object RdfFromJelly extends JellyCommand[FromJellyRdfOptions]: | ||
| override def names: List[List[String]] = List( | ||
| List("rdf", "from-jelly"), | ||
| ) | ||
|
|
||
| override def run(options: FromJellyRdfOptions, remainingArgs: RemainingArgs): Unit = | ||
| // This is a placeholder for the actual implementation | ||
| println("rdf from-jelly") | ||
| println(options) | ||
| println(remainingArgs) | ||
| override def run(options: RdfFromJellyOptions, remainingArgs: RemainingArgs): Unit = | ||
| val inputStream = options.inputFile match { | ||
| case Some(fileName: String) => | ||
| FileInputStream(File(fileName)) | ||
| case None => System.in | ||
| } | ||
| rewriteFormats(inputStream) | ||
Karolina-Bogacka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /* | ||
| This method reads the Jelly file, rewrite it to NQuads and writes it to the output stream | ||
| * @param inputStream InputStream | ||
| */ | ||
| private def rewriteFormats(inputStream: InputStream): Unit = | ||
| // TODO: Add error handling; return success/failure in the future | ||
| val interStream = new ByteArrayOutputStream() | ||
| val interWriter = StreamRDFWriter.getWriterStream(interStream, RDFLanguages.NQUADS) | ||
| RDFParser.source(inputStream).lang(JellyLanguage.JELLY).parse(interWriter) | ||
| val readerStream = new ByteArrayInputStream(interStream.toByteArray) | ||
| val nQuadWriter = StreamRDFWriter.getWriterStream(getOutputStream, RDFLanguages.NQUADS) | ||
| RDFParser.source(readerStream).lang(RDFLanguages.NQUADS).parse(nQuadWriter) | ||
Ostrzyciel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Binary file added
BIN
+45.7 KB
src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfFromJelly.scala.semanticdb
Binary file not shown.
19 changes: 18 additions & 1 deletion
19
src/test/scala/eu/neverblink/jelly/cli/command/RdfFromJellySpec.scala
This file contains hidden or 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 |
|---|---|---|
| @@ -1,12 +1,29 @@ | ||
| package eu.neverblink.jelly.cli.command | ||
|
|
||
| import eu.neverblink.jelly.cli.command.helpers.* | ||
| import eu.neverblink.jelly.cli.command.rdf.* | ||
| import org.scalatest.matchers.should.Matchers | ||
| import org.scalatest.wordspec.AnyWordSpec | ||
|
|
||
| class RdfFromJellySpec extends AnyWordSpec with Matchers with CleanUpFilesAfterTest: | ||
| class RdfFromJellySpec extends AnyWordSpec with Matchers with CleanUpAfterTest: | ||
| "rdf from-jelly command" should { | ||
| "be able to convert a Jelly file to NTriples" in { | ||
| val jellyFile = DataGenHelper.generateJellyFile(3) | ||
| val nQuadString = DataGenHelper.generateNQuadString(3) | ||
| val options = RdfFromJellyOptions(inputFile = Some(jellyFile)) | ||
| val (out, err) = RdfFromJelly.runTest(options) | ||
| val sortedOut = out.split("\n").map(_.trim).sorted | ||
| val sortedQuads = nQuadString.split("\n").map(_.trim).sorted | ||
| sortedOut should contain theSameElementsAs sortedQuads | ||
| } | ||
| "be able to convert a Jelly stream to NTriples" in { | ||
| val jellyStream = DataGenHelper.generateJellyInputStream(3) | ||
| System.setIn(jellyStream) | ||
| val nQuadString = DataGenHelper.generateNQuadString(3) | ||
| val options = RdfFromJellyOptions(inputFile = None) | ||
| val (out, err) = RdfFromJelly.runTest(options) | ||
| val sortedOut = out.split("\n").map(_.trim).sorted | ||
| val sortedQuads = nQuadString.split("\n").map(_.trim).sorted | ||
| sortedOut should contain theSameElementsAs sortedQuads | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.