Skip to content

Commit 77ca24a

Browse files
authored
Don’t output stack trace unless --verbose is passed. Support option for --disable-owl-nothing. (#102)
1 parent c22748a commit 77ca24a

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/main/scala/org/renci/relationgraph/Config.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ final case class Config(ontologyFile: String,
1111
propertiesFile: Option[String],
1212
outputSubclasses: BoolValue = FalseValue,
1313
reflexiveSubclasses: BoolValue = TrueValue,
14-
equivalenceAsSubclass: BoolValue = TrueValue) {
15-
16-
}
14+
equivalenceAsSubclass: BoolValue = TrueValue,
15+
disableOwlNothing: BoolValue = FalseValue,
16+
verbose: Boolean = false)
1717

1818
object Config {
1919

src/main/scala/org/renci/relationgraph/Main.scala

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import org.semanticweb.owlapi.apibinding.OWLFunctionalSyntaxFactory.{OWLNothing,
1313
import org.semanticweb.owlapi.apibinding.OWLManager
1414
import org.semanticweb.owlapi.model._
1515
import org.semanticweb.owlapi.model.parameters.Imports
16+
import scribe.Level
17+
import scribe.filter.{packageName, select}
1618
import zio._
1719
import zio.blocking._
1820
import zio.stream._
@@ -38,14 +40,22 @@ object Main extends ZCaseApp[Config] {
3840
private val OWLOntology = OWL2.Ontology.asNode
3941

4042
override def run(config: Config, arg: RemainingArgs): ZIO[ZEnv, Nothing, ExitCode] = {
43+
val configureLogging = ZIO.succeed {
44+
scribe.Logger.root
45+
.clearHandlers()
46+
.clearModifiers()
47+
.withModifier(select(packageName("org.renci.relationgraph")).boosted(Level.Info, Level.Warn))
48+
.withHandler(minimumLevel = Some(if (config.verbose) Level.Info else Level.Warn))
49+
.replace()
50+
}
4151
val program = createStreamRDF(config.outputFile).use { rdfWriter =>
4252
for {
4353
fileProperties <- config.propertiesFile.map(readPropertiesFile).getOrElse(ZIO.succeed(Set.empty[AtomicConcept]))
4454
specifiedProperties = fileProperties ++ config.property.map(prop => AtomicConcept(prop)).to(Set)
4555
ontology <- loadOntology(config.ontologyFile)
4656
whelkOntology = Bridge.ontologyToAxioms(ontology)
4757
_ <- ZIO.succeed(scribe.info("Running reasoner"))
48-
whelk = Reasoner.assert(whelkOntology)
58+
whelk = Reasoner.assert(whelkOntology, disableBottom = config.disableOwlNothing.bool)
4959
indexedWhelk = IndexedReasonerState(whelk)
5060
_ <- ZIO.succeed(scribe.info("Done running reasoner"))
5161
_ <- ZIO.fail(new Exception("Ontology is incoherent; please correct unsatisfiable classes.")).when(isIncoherent(whelk))
@@ -60,7 +70,12 @@ object Main extends ZCaseApp[Config] {
6070
_ <- ZIO.succeed(scribe.info(s"Computed relations in ${(stop - start) / 1000.0}s"))
6171
} yield ()
6272
}
63-
program.exitCode
73+
configureLogging *>
74+
program.as(ExitCode.success)
75+
.catchAll { e =>
76+
if (config.verbose) ZIO.succeed(e.printStackTrace()).as(ExitCode.failure)
77+
else ZIO.succeed(scribe.error(e.getMessage)).as(ExitCode.failure)
78+
}
6479
}
6580

6681
def computeRelations(ontology: OWLOntology, whelk: IndexedReasonerState, specifiedProperties: Set[AtomicConcept], outputSubclasses: Boolean, reflexiveSubclasses: Boolean, equivalenceAsSubclass: Boolean, mode: Config.OutputMode): UStream[TriplesGroup] = {

0 commit comments

Comments
 (0)