Prepare: added command-line parameters parsing
This commit is contained in:
parent
e4902fe995
commit
67a3654451
|
|
@ -14,6 +14,7 @@ dependencies {
|
|||
implementation 'org.apache.jena:apache-jena-libs:4.4.0'
|
||||
implementation 'org.apache.logging.log4j:log4j-core:2.17.2'
|
||||
implementation 'org.slf4j:slf4j-simple:1.7.36'
|
||||
implementation 'net.sourceforge.argparse4j:argparse4j:0.9.0'
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
|
@ -35,7 +36,7 @@ compileJava {
|
|||
}
|
||||
|
||||
application {
|
||||
mainClass = "Main"
|
||||
mainClass = "guessNNprepare.Main"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package guessNNprepare
|
||||
|
||||
import guessNNprepare.mains.ExtractEntities
|
||||
import net.sourceforge.argparse4j.ArgumentParsers
|
||||
import net.sourceforge.argparse4j.inf.{ArgumentParser, ArgumentParserException, Namespace}
|
||||
|
||||
object Main {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val parser: ArgumentParser = ArgumentParsers.newFor("GuessNN-prepare").singleMetavar(true).build()
|
||||
val subParsers = parser.addSubparsers().dest("command").title("Commands").metavar("COMMAND").help("Command to execute")
|
||||
ExtractEntities.addCliArgs(subParsers.addParser("entities").help(ExtractEntities.description))
|
||||
|
||||
try {
|
||||
val ARGS: Namespace = parser.parseArgs(args)
|
||||
val command = ARGS.getString("command")
|
||||
command match {
|
||||
case "entities" => ExtractEntities.execute(ARGS)
|
||||
case _ =>
|
||||
System.err.printf(s"Unknown command ${command}");
|
||||
System.exit(1)
|
||||
}
|
||||
} catch {
|
||||
case e: ArgumentParserException =>
|
||||
parser.handleError(e)
|
||||
System.exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
package guessNNprepare
|
||||
|
||||
import org.apache.jena.rdf.model.Resource
|
||||
|
||||
class NamedEntity(val rdfResource: Resource, val Name: String, val readableType: String) {
|
||||
|
|
@ -1,11 +1,27 @@
|
|||
package guessNNprepare.mains
|
||||
|
||||
import guessNNprepare.NamedEntity
|
||||
import net.sourceforge.argparse4j.impl.Arguments
|
||||
import net.sourceforge.argparse4j.inf.{ArgumentParser, Namespace}
|
||||
import org.apache.jena.query.QueryExecutionFactory
|
||||
import org.apache.jena.rdf.model.{InfModel, Model, ModelFactory}
|
||||
import org.apache.jena.reasoner.ReasonerRegistry
|
||||
|
||||
import java.io.InputStream
|
||||
|
||||
object Main extends App {
|
||||
{
|
||||
object ExtractEntities extends MainCommand {
|
||||
|
||||
override def description: String = "Save the list of guessable entities to a json file"
|
||||
|
||||
override def addCliArgs(parser: ArgumentParser): Unit = {
|
||||
parser.description(description)
|
||||
|
||||
parser.addArgument("json_file").`type`(Arguments.fileType().verifyCanWriteParent()).help("Where the guessable entities will be saved")
|
||||
}
|
||||
|
||||
override def execute(ARGS: Namespace): Unit = {
|
||||
val jsonFilePath = ARGS.getString("json_file")
|
||||
|
||||
println("Loading knowledge graph...")
|
||||
val kg: InfModel = ModelFactory.createInfModel(ReasonerRegistry.getTransitiveReasoner, ModelFactory.createDefaultModel)
|
||||
val mondialDataset: InputStream = Option(ClassLoader.getSystemResourceAsStream("mondial_2022_04_04.n3"))
|
||||
|
|
@ -23,6 +39,7 @@ object Main extends App {
|
|||
getMondialNamedEntities(kg, "Sea"))
|
||||
.distinct
|
||||
printf("Found %d guessable named entities\n", guessableEntities.size)
|
||||
println(s"They would be written to ${jsonFilePath} (not implemented yet)")
|
||||
}
|
||||
|
||||
def getMondialNamedEntities(kg: Model, prefixedType: String): List[NamedEntity] = {
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package guessNNprepare.mains
|
||||
|
||||
import net.sourceforge.argparse4j.inf.{ArgumentParser, Namespace}
|
||||
|
||||
trait MainCommand {
|
||||
|
||||
def description: String
|
||||
|
||||
def addCliArgs(parser: ArgumentParser): Unit
|
||||
|
||||
def execute(ARGS: Namespace): Unit
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue