diff --git a/.scalafmt.conf b/.scalafmt.conf index a58b60d..e23387c 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 2.6.4 +version = 2.7.5 maxColumn = 140 continuationIndent.callSite = 2 continuationIndent.defnSite = 2 diff --git a/src/main/scala/org/renci/relationgraph/Config.scala b/src/main/scala/org/renci/relationgraph/Config.scala index c859349..76ede7c 100644 --- a/src/main/scala/org/renci/relationgraph/Config.scala +++ b/src/main/scala/org/renci/relationgraph/Config.scala @@ -12,9 +12,7 @@ final case class Config(ontologyFile: String, propertiesFile: Option[String], outputSubclasses: BoolValue = FalseValue, reflexiveSubclasses: BoolValue = TrueValue, - equivalenceAsSubclass: BoolValue = TrueValue) { - -} + equivalenceAsSubclass: BoolValue = TrueValue) {} object Config { @@ -30,15 +28,14 @@ object Config { arg.toLowerCase match { case "rdf" => Right(RDFMode) case "owl" => Right(OWLMode) - case _ => Left(MalformedValue("output mode", arg)) + case _ => Left(MalformedValue("output mode", arg)) } } } - /** - * This works around some confusing behavior in case-app boolean parsing - */ + /** This works around some confusing behavior in case-app boolean parsing + */ sealed trait BoolValue { def bool: Boolean @@ -59,11 +56,11 @@ object Config { implicit val argParser: ArgParser[BoolValue] = SimpleArgParser.from[BoolValue]("boolean value") { arg => arg.toLowerCase match { - case "true" => Right(TrueValue) + case "true" => Right(TrueValue) case "false" => Right(FalseValue) - case "1" => Right(TrueValue) - case "0" => Right(FalseValue) - case _ => Left(MalformedValue("boolean value", arg)) + case "1" => Right(TrueValue) + case "0" => Right(FalseValue) + case _ => Left(MalformedValue("boolean value", arg)) } } diff --git a/src/main/scala/org/renci/relationgraph/Main.scala b/src/main/scala/org/renci/relationgraph/Main.scala index 8cbdf9a..16707c2 100644 --- a/src/main/scala/org/renci/relationgraph/Main.scala +++ b/src/main/scala/org/renci/relationgraph/Main.scala @@ -49,37 +49,35 @@ object Main extends ZCaseApp[Config] { nonredundantRDFWriter <- createStreamRDF(nonredundantOutputStream) redundantRDFWriter <- createStreamRDF(redundantOutputStream) } yield (nonredundantRDFWriter, redundantRDFWriter) - val program = streamsManaged.use { - case (nonredundantRDFWriter, redundantRDFWriter) => - for { - fileProperties <- config.propertiesFile.map(readPropertiesFile).getOrElse(ZIO.succeed(Set.empty[OWLObjectProperty])) - specifiedProperties = fileProperties ++ config.property.map(prop => df.getOWLObjectProperty(IRI.create(prop))).to(Set) - manager <- ZIO.effect(OWLManager.createOWLOntologyManager()) - ontology <- ZIO.effect(manager.loadOntologyFromOntologyDocument(ontologyFile)) - whelkOntology = Bridge.ontologyToAxioms(ontology) - _ <- ZIO.effectTotal(scribe.info("Running reasoner")) - whelk = Reasoner.assert(whelkOntology) - _ <- ZIO.effectTotal(scribe.info("Done running reasoner")) - _ <- (effectBlockingIO( - nonredundantRDFWriter.triple(Triple.create(NodeFactory.createBlankNode("nonredundant"), RDFType, OWLOntology))) *> - effectBlockingIO(redundantRDFWriter.triple(Triple.create(NodeFactory.createBlankNode("redundant"), RDFType, OWLOntology)))) - .when(config.mode == OWLMode) - start <- ZIO.effectTotal(System.currentTimeMillis()) - classes = allClasses(ontology) - classesTasks = classes.map(c => Task(processSuperclasses(c, whelk, config))) - restrictions = extractAllRestrictions(ontology, specifiedProperties) - restrictionsTasks = restrictions.map(r => Task(processRestriction(r, whelk, config.mode))) - allTasks = classesTasks ++ restrictionsTasks - processed = allTasks.mapParallelUnordered(JRuntime.getRuntime.availableProcessors)(identity) - monixTask = processed.foreachL { - case TriplesGroup(nonredundant, redundant) => - nonredundant.foreach(nonredundantRDFWriter.triple) - redundant.foreach(redundantRDFWriter.triple) - } - _ <- IO.fromTask(monixTask) - stop <- ZIO.effectTotal(System.currentTimeMillis()) - _ <- ZIO.effectTotal(scribe.info(s"Computed relations in ${(stop - start) / 1000.0}s")) - } yield () + val program = streamsManaged.use { case (nonredundantRDFWriter, redundantRDFWriter) => + for { + fileProperties <- config.propertiesFile.map(readPropertiesFile).getOrElse(ZIO.succeed(Set.empty[OWLObjectProperty])) + specifiedProperties = fileProperties ++ config.property.map(prop => df.getOWLObjectProperty(IRI.create(prop))).to(Set) + manager <- ZIO.effect(OWLManager.createOWLOntologyManager()) + ontology <- ZIO.effect(manager.loadOntologyFromOntologyDocument(ontologyFile)) + whelkOntology = Bridge.ontologyToAxioms(ontology) + _ <- ZIO.effectTotal(scribe.info("Running reasoner")) + whelk = Reasoner.assert(whelkOntology) + _ <- ZIO.effectTotal(scribe.info("Done running reasoner")) + _ <- (effectBlockingIO( + nonredundantRDFWriter.triple(Triple.create(NodeFactory.createBlankNode("nonredundant"), RDFType, OWLOntology))) *> + effectBlockingIO(redundantRDFWriter.triple(Triple.create(NodeFactory.createBlankNode("redundant"), RDFType, OWLOntology)))) + .when(config.mode == OWLMode) + start <- ZIO.effectTotal(System.currentTimeMillis()) + classes = allClasses(ontology) + classesTasks = classes.map(c => Task(processSuperclasses(c, whelk, config))) + restrictions = extractAllRestrictions(ontology, specifiedProperties) + restrictionsTasks = restrictions.map(r => Task(processRestriction(r, whelk, config.mode))) + allTasks = classesTasks ++ restrictionsTasks + processed = allTasks.mapParallelUnordered(JRuntime.getRuntime.availableProcessors)(identity) + monixTask = processed.foreachL { case TriplesGroup(nonredundant, redundant) => + nonredundant.foreach(nonredundantRDFWriter.triple) + redundant.foreach(redundantRDFWriter.triple) + } + _ <- IO.fromTask(monixTask) + stop <- ZIO.effectTotal(System.currentTimeMillis()) + _ <- ZIO.effectTotal(scribe.info(s"Computed relations in ${(stop - start) / 1000.0}s")) + } yield () } program.exitCode } @@ -98,7 +96,8 @@ object Main extends ZCaseApp[Config] { } }(stream => ZIO.effectTotal(stream.finish())) - def allClasses(ont: OWLOntology): Observable[OWLClass] = Observable.fromIterable(ont.getClassesInSignature(Imports.INCLUDED).asScala.to(Set) - OWLThing - OWLNothing) + def allClasses(ont: OWLOntology): Observable[OWLClass] = + Observable.fromIterable(ont.getClassesInSignature(Imports.INCLUDED).asScala.to(Set) - OWLThing - OWLNothing) def processSuperclasses(cls: OWLClass, whelk: ReasonerState, config: Config): TriplesGroup = { val subject = NodeFactory.createURI(cls.getIRI.toString) @@ -110,19 +109,21 @@ object Main extends ZCaseApp[Config] { val (equivs, directSuperclasses) = whelk.directlySubsumedBy(concept) val adjustedEquivs = if (config.reflexiveSubclasses.bool) equivs + concept else equivs - concept val directSuperclassTriples = directSuperclasses.map(c => Triple.create(subject, RDFSSubClassOf, NodeFactory.createURI(c.id))) - val equivalentClassTriples = if (config.equivalenceAsSubclass.bool) - adjustedEquivs.map(c => Triple.create(subject, RDFSSubClassOf, NodeFactory.createURI(c.id))) - else - adjustedEquivs.map(c => Triple.create(subject, OWLEquivalentClass, NodeFactory.createURI(c.id))) + val equivalentClassTriples = + if (config.equivalenceAsSubclass.bool) + adjustedEquivs.map(c => Triple.create(subject, RDFSSubClassOf, NodeFactory.createURI(c.id))) + else + adjustedEquivs.map(c => Triple.create(subject, OWLEquivalentClass, NodeFactory.createURI(c.id))) val nonredundantTriples = directSuperclassTriples ++ equivalentClassTriples val adjustedSuperclasses = if (config.reflexiveSubclasses.bool) allSuperclasses + concept else allSuperclasses - concept - val redundantTriples = if (config.equivalenceAsSubclass.bool) - adjustedSuperclasses.map(c => Triple.create(subject, RDFSSubClassOf, NodeFactory.createURI(c.id))) - else { - val superclassesMinusEquiv = adjustedSuperclasses -- adjustedEquivs - superclassesMinusEquiv.map(c => Triple.create(subject, RDFSSubClassOf, NodeFactory.createURI(c.id))) ++ - equivalentClassTriples - } + val redundantTriples = + if (config.equivalenceAsSubclass.bool) + adjustedSuperclasses.map(c => Triple.create(subject, RDFSSubClassOf, NodeFactory.createURI(c.id))) + else { + val superclassesMinusEquiv = adjustedSuperclasses -- adjustedEquivs + superclassesMinusEquiv.map(c => Triple.create(subject, RDFSSubClassOf, NodeFactory.createURI(c.id))) ++ + equivalentClassTriples + } TriplesGroup(nonredundantTriples, redundantTriples) } } diff --git a/src/main/scala/org/renci/relationgraph/ZCaseApp.scala b/src/main/scala/org/renci/relationgraph/ZCaseApp.scala index f49dd1b..8203f1d 100644 --- a/src/main/scala/org/renci/relationgraph/ZCaseApp.scala +++ b/src/main/scala/org/renci/relationgraph/ZCaseApp.scala @@ -8,8 +8,7 @@ import caseapp.core.{Error, RemainingArgs} import zio._ import zio.console.{putStrLn, Console} -/** - * Adapted from caseapp.cats.IOCaseApp +/** Adapted from caseapp.cats.IOCaseApp */ abstract class ZCaseApp[T](implicit val parser0: Parser[T], val messages: Help[T]) extends App { @@ -32,8 +31,7 @@ abstract class ZCaseApp[T](implicit val parser0: Parser[T], val messages: Help[T private[this] def usageAsked: ZIO[Console, Nothing, ExitCode] = putStrLn(messages.withHelp.usage).as(ExitCode.success) - /** - * Arguments are expanded then parsed. By default, argument expansion is the identity function. + /** Arguments are expanded then parsed. By default, argument expansion is the identity function. * Overriding this method allows plugging in an arbitrary argument expansion logic. * * One such expansion logic involves replacing each argument of the form '@' with the @@ -51,8 +49,7 @@ abstract class ZCaseApp[T](implicit val parser0: Parser[T], val messages: Help[T */ private[this] def expandArgs(args: List[String]): List[String] = args - /** - * Whether to stop parsing at the first unrecognized argument. + /** Whether to stop parsing at the first unrecognized argument. * * That is, stop parsing at the first non option (not starting with "-"), or * the first unrecognized option. The unparsed arguments are put in the `args` diff --git a/src/test/scala/org/renci/relationgraph/TestRelationGraph.scala b/src/test/scala/org/renci/relationgraph/TestRelationGraph.scala index 853e96c..ee7da03 100644 --- a/src/test/scala/org/renci/relationgraph/TestRelationGraph.scala +++ b/src/test/scala/org/renci/relationgraph/TestRelationGraph.scala @@ -30,7 +30,8 @@ object TestRelationGraph extends DefaultRunnableSpec { restrictions .map(Main.processRestriction(_, whelk, Config.RDFMode)) .reduce((left, right) => TriplesGroup(left.nonredundant ++ right.nonredundant, left.redundant ++ right.redundant)) - .headL) + .headL + ) TriplesGroup(nonredundant, redundant) = triples } yield assert(nonredundant)(contains(Triple.create(n(s"$Prefix#A"), P, n(s"$Prefix#D")))) && assert(redundant)(contains(Triple.create(n(s"$Prefix#A"), P, n(s"$Prefix#D")))) &&