Prepare: fix so that CNN library can be called without runtime errors
This commit is contained in:
parent
ef3d96d024
commit
815e9f1b1f
|
|
@ -11,7 +11,7 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
implementation 'org.scala-lang:scala3-library_3:3.1.2'
|
||||
implementation 'org.apache.jena:apache-jena-libs:4.4.0'
|
||||
implementation 'org.apache.jena:apache-jena-libs:3.17.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'
|
||||
|
|
|
|||
|
|
@ -22,12 +22,14 @@ object ComputeConcepts extends MainCommand {
|
|||
|
||||
parser.addArgument("guessable_entities").`type`(Arguments.fileType().verifyCanRead()).help("JSON file containing all guessable entities")
|
||||
parser.addArgument("target").help("URI of the entity that should be guessed")
|
||||
parser.addArgument("json_output").`type`(Arguments.fileType().verifyCanWrite().or().verifyCanWriteParent()).help("JSON file where the concepts will be saved")
|
||||
}
|
||||
|
||||
override def execute(ARGS: Namespace): Unit = {
|
||||
// CLI args
|
||||
val entitiesFilePath = Paths.get(ARGS.getString("guessable_entities"))
|
||||
val guessTarget = ARGS.getString("target")
|
||||
val outputFilePath = Paths.get(ARGS.getString("json_output"))
|
||||
|
||||
println(s"Loading entities from ${entitiesFilePath}")
|
||||
val entities: List[NamedEntity] = loadEntitiesOrFail(entitiesFilePath)
|
||||
|
|
@ -40,18 +42,25 @@ object ComputeConcepts extends MainCommand {
|
|||
val dataGraph = Utils.loadMondialDataset().get
|
||||
println(s"Loaded ${dataGraph.listStatements().toList.size()} triples")
|
||||
|
||||
val entityVar = Var.alloc("e")
|
||||
val entityVar = Var.alloc("Neighbor_0")
|
||||
val entityTable = new Table(List(entityVar).asJava)
|
||||
entities
|
||||
.map(entity => dataGraph.createResource(entity.rdfResource))
|
||||
.map(entity => dataGraph.createResource(entity.rdfResource.getURI))
|
||||
.map(resource => resource.asNode())
|
||||
.map(node => BindingFactory.binding(entityVar, node))
|
||||
.foreach(binding => entityTable.addBinding(binding))
|
||||
|
||||
val cnnPartition = new Partition(new ConceptualKNNModel(dataGraph), List(guessTarget).asJava, entityTable, 0)
|
||||
val cnnPartition = new Partition(new ConceptualKNNModel(dataGraph), List(guessTarget).asJava, entityTable, -1)
|
||||
println("Starting concept computation")
|
||||
cnnPartition.fullPartitioning(new AtomicBoolean(false))
|
||||
println(s"Computation finished, ${cnnPartition.getNbConcepts} concepts computed")
|
||||
val stop = new AtomicBoolean(false)
|
||||
val partitionThread = new Thread(() => cnnPartition.fullPartitioning(stop))
|
||||
val startTime = System.currentTimeMillis()
|
||||
partitionThread.start()
|
||||
partitionThread.join(60000)
|
||||
stop.set(true)
|
||||
partitionThread.join()
|
||||
println(s"Concept computation finished, ${(System.currentTimeMillis() - startTime)/1000}s elapsed.")
|
||||
Files.writeString(outputFilePath, cnnPartition.toJson)
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue