(************************************************************************* * Copyright (C) * 2019-2023 The University of Exeter * 2018-2023 The University of Paris-Saclay * 2018 The University of Sheffield * * License: * This program can be redistributed and/or modified under the terms * of the 2-clause BSD-style license. * * SPDX-License-Identifier: BSD-2-Clause *************************************************************************) chapter\Creating and Referencing Ontological Instances\ theory Concept_OntoReferencing imports "TestKit" "Isabelle_DOF-Unit-Tests_document" "Isabelle_DOF-Ontologies.Conceptual" begin section\Test Purpose.\ text\ Creation of ontological instances along the \<^theory>\Isabelle_DOF-Ontologies.Conceptual\ Ontology. Emphasis is put on type-safe (ontologically consistent) referencing of text, code and proof elements. Some tests cover also the critical cases concerning name spaces of oid's. \ section\Setting up a monitor.\ text\\<^theory>\Isabelle_DOF-Ontologies.Conceptual\ provides a monitor \<^typ>\M\ enforcing a particular document structure. Here, we say: From now on, this structural rules are respected wrt. all \<^theory_text>\doc_classes M\ is enabled for.\ open_monitor*[struct::M] section\Defining Text Elements and Referring to them... \ text\ This uses elements of two ontologies, notably \<^theory>\Isabelle_DOF-Ontologies.Conceptual\ and \<^theory>\Isabelle_DOF.Isa_COL\.\ (*<*) title*[ag::title, short_title="Some\ooups.\"]\Lorem ipsum dolor sit amet ...\ subtitle*[af::subtitle, abbrev = "Some\ooups-oups.\"]\Lorem ipsum dolor sit amet ...\ chapter*[a0::A, x = "3"] \ Lorem ipsum dolor sit amet ... \ section*[a::A, x = "3"] \ Lorem ipsum dolor sit amet, ... \ subsection*[ab::A, x = "3"] \ Lorem ipsum dolor sit amet, ... As mentioned in the @{title \ag\}... \ \ \old-style and ...\ subsubsection*[ac::A, x = "3"] \ Lorem ipsum dolor sit amet, ... As mentioned in the \<^title>\ag\\ \ \new-style references to ontological instances assigned to text elements ...\ (*>*) text\Meta-Objects are typed, and references have to respect this : \ (*<*) text-assert-error[ad]\ \<^title>\a\ \ \reference ontologically inconsistent\ text-assert-error[ae]\ \<^title>\af\ \\reference ontologically inconsistent\ \ \erroneous reference: please consider class hierarchy!\ (*>*) text\References to Meta-Objects can be forward-declared:\ text-assert-error[ae1]\@{C \c1\}\\Undefined instance:\ declare_reference*[c1::C] \ \forward declaration\ text-assert-error\@{C \c1\} \\Instance declared but not defined, try option unchecked\ text\@{C (unchecked) \c1\} \ text*[a1::A, level="Some 0", x = 3]\... phasellus amet id massa nunc, ...\ text*[c1::C, x = "''beta''"] \ ... suspendisse non arcu malesuada mollis, nibh morbi, ... \ text-assert-error[c1::C, x = "''gamma''"] \ ... suspendisse non arcu malesuada mollis, nibh morbi, ... \ \Duplicate instance declaration\ \ \Referencing from a text context:\ text*[d::D, a1 = "X3"] \ ... phasellus amet id massa nunc, pede suscipit repellendus, ... @{C "c1"} or @{C \c1\} or \<^C>\c1\ similar to @{thm "refl"} and \<^thm>"refl"\ \ \ontological and built-in references\ text\Not only text-elements are "ontology-aware", proofs and code can this be too !\ \ \Referencing from and to a ML-code context:\ ML*[c4::C, z = "Some @{A \a1\}"]\ fun fac x = if x = 0 then 1 else x * (fac(x-1)) val v = \<^value_>\A.x (the (z @{C \c4\}))\ |> HOLogic.dest_number |> snd |> fac \ definition*[a2::A, x=5, level="Some 1"] xx' where "xx' \ A.x @{A \a1\}" if "A.x @{A \a1\} = 5" lemma*[e5::E] testtest : "xx + A.x @{A \a1\} = yy + A.x @{A \a1\} \ xx = yy" by simp declare_reference-assert-error[c1::C]\Duplicate instance declaration\ \ \forward declaration\ declare_reference*[e6::E] text\This is the answer to the "OutOfOrder Presentation Problem": @{E (unchecked) \e6\} \ definition*[e6::E] facu :: "nat \ nat" where "facu arg = undefined" text\As shown in @{E \e5\} following from @{E \e6\}\ text\As shown in @{C \c4\}\ text\Ontological information ("class instances") is mutable: \ update_instance*[d::D, a1 := X2] text\ ... in ut tortor ... @{docitem \a\} ... @{A \a\} ... \ \ \untyped or typed referencing \ text-assert-error[ae::text_element]\the function @{C [display] "c4"} \\referred text-element is no macro!\ text*[c2::C, x = "\delta\"] \ ... in ut tortor eleifend augue pretium consectetuer. \ text\Note that both the notations @{term "''beta''"} and @{term "\beta\"} are possible; the former is a more ancient format only supporting pure ascii, while the latter also supports fancy unicode such as: @{term "\\\<^sub>i''\"} \ text*[f::F] \ Lectus accumsan velit ultrices, ... \ theorem some_proof : "True" by simp text\This is an example where we add a theorem into a kind of "result-list" of the doc-item f.\ update_instance*[f::F,r:="[@{thm ''Concept_OntoReferencing.some_proof''}]"] text\ ..., mauris amet, id elit aliquam aptent id, ... @{docitem \a\} \ text\Here we add and maintain a link that is actually modeled as m-to-n relation ...\ update_instance*[f::F,b:="{(@{docitem \a\}::A,@{docitem \c1\}::C), (@{docitem \a\}, @{docitem \c2\})}"] section\Closing the Monitor and testing the Results.\ close_monitor*[struct] text\And the trace of the monitor is:\ ML\val trace = @{trace_attribute struct}\ ML\@{assert} (trace = [("Conceptual.A", "a0"), ("Conceptual.A", "a"), ("Conceptual.A", "ab"), ("Conceptual.A", "ac"), ("Conceptual.A", "a1"), ("Conceptual.C", "c1"), ("Conceptual.D", "d"), ("Conceptual.C", "c4"), ("Conceptual.A", "a2"), ("Conceptual.E", "e5"), ("Conceptual.E", "e6"), ("Conceptual.C", "c2"), ("Conceptual.F", "f")]) \ text\Note that the monitor \<^typ>\M\ of the ontology \<^theory>\Isabelle_DOF-Ontologies.Conceptual\ does not observe the common entities of \<^theory>\Isabelle_DOF.Isa_COL\, but just those defined in the accept- clause of \<^typ>\M\.\ text\One final check of the status DOF core: observe that no new classes have been defined, just a couple of new document elements have been introduced.\ print_doc_classes print_doc_items end