2018-04-05 10:09:58 +00:00
|
|
|
section{* An example ontology for a scholarly paper*}
|
2018-03-27 07:41:39 +00:00
|
|
|
|
2018-04-05 10:09:58 +00:00
|
|
|
theory scholarly_paper
|
2018-10-23 11:56:18 +00:00
|
|
|
imports "../Isa_COL"
|
2018-03-21 10:59:27 +00:00
|
|
|
begin
|
|
|
|
|
|
|
|
doc_class title =
|
2018-04-17 13:08:01 +00:00
|
|
|
short_title :: "string option" <= "None"
|
|
|
|
|
2018-03-21 10:59:27 +00:00
|
|
|
doc_class subtitle =
|
2018-04-17 15:39:16 +00:00
|
|
|
abbrev :: "string option" <= "None"
|
2018-03-27 07:41:39 +00:00
|
|
|
|
|
|
|
-- \<open>adding a contribution list and checking that it is cited as well in tech as in conclusion. ? \<close>
|
2018-03-21 10:59:27 +00:00
|
|
|
|
|
|
|
doc_class author =
|
2018-11-27 11:53:02 +00:00
|
|
|
email :: "string" <= "''''"
|
|
|
|
http_site :: "string" <= "''''"
|
|
|
|
orcid :: "string" <= "''''"
|
2018-03-21 10:59:27 +00:00
|
|
|
affiliation :: "string"
|
|
|
|
|
|
|
|
doc_class abstract =
|
2018-04-30 08:48:14 +00:00
|
|
|
keywordlist :: "string list" <= "[]"
|
|
|
|
principal_theorems :: "thm list"
|
2018-04-27 08:34:24 +00:00
|
|
|
|
2019-02-12 21:13:28 +00:00
|
|
|
doc_class text_section = text_element +
|
2018-04-05 10:09:58 +00:00
|
|
|
main_author :: "author option" <= None
|
2018-05-01 09:38:56 +00:00
|
|
|
fixme_list :: "string list" <= "[]"
|
2018-11-28 09:49:35 +00:00
|
|
|
level :: "int option" <= "None"
|
2019-02-12 21:13:28 +00:00
|
|
|
(* this attribute enables doc-notation support section* etc.
|
|
|
|
we follow LaTeX terminology on levels
|
|
|
|
part = Some -1
|
|
|
|
chapter = Some 0
|
|
|
|
section = Some 1
|
|
|
|
subsection = Some 2
|
|
|
|
subsubsection = Some 3
|
|
|
|
... *)
|
2018-11-28 09:49:35 +00:00
|
|
|
(* for scholarly paper: invariant level > 0 *)
|
2018-11-07 05:00:01 +00:00
|
|
|
|
2018-03-27 07:41:39 +00:00
|
|
|
doc_class introduction = text_section +
|
2018-04-27 15:12:42 +00:00
|
|
|
comment :: string
|
2018-05-01 09:38:56 +00:00
|
|
|
claims :: "thm list"
|
2018-03-21 10:59:27 +00:00
|
|
|
|
2018-03-27 07:41:39 +00:00
|
|
|
doc_class technical = text_section +
|
2018-04-05 10:09:58 +00:00
|
|
|
definition_list :: "string list" <= "[]"
|
2018-04-30 08:48:14 +00:00
|
|
|
formal_results :: "thm list"
|
2018-04-27 08:34:24 +00:00
|
|
|
|
2018-04-17 13:58:11 +00:00
|
|
|
text{* A very rough formatting style could be modeled as follows:*}
|
|
|
|
|
|
|
|
|
|
|
|
doc_class example = text_section +
|
|
|
|
comment :: "string"
|
2018-03-27 07:41:39 +00:00
|
|
|
|
2018-05-15 07:11:17 +00:00
|
|
|
doc_class "conclusion" = text_section +
|
2018-04-05 10:09:58 +00:00
|
|
|
main_author :: "author option" <= None
|
2018-03-28 07:24:27 +00:00
|
|
|
|
2018-05-15 07:11:17 +00:00
|
|
|
doc_class related_work = "conclusion" +
|
2018-04-05 10:09:58 +00:00
|
|
|
main_author :: "author option" <= None
|
2018-03-21 10:59:27 +00:00
|
|
|
|
2018-12-18 13:29:08 +00:00
|
|
|
doc_class bibliography = text_section +
|
2018-12-11 15:03:01 +00:00
|
|
|
style :: "string option" <= "Some ''LNCS''"
|
2018-03-21 10:59:27 +00:00
|
|
|
|
2018-12-19 11:05:57 +00:00
|
|
|
doc_class annex = "text_section" +
|
|
|
|
main_author :: "author option" <= None
|
|
|
|
|
|
|
|
|
2018-10-16 08:44:59 +00:00
|
|
|
text\<open> Besides subtyping, there is another relation between
|
|
|
|
doc_classes: a class can be a \<^emph>\<open>monitor\<close> to other ones,
|
|
|
|
which is expressed by occurrence in the where clause.
|
|
|
|
While sub-classing refers to data-inheritance of attributes,
|
|
|
|
a monitor captures structural constraints -- the order --
|
|
|
|
in which instances of monitored classes may occur.
|
|
|
|
|
|
|
|
The control of monitors is done by the commands:
|
|
|
|
\<^item> \<^verbatim>\<open> monitor <oid::class_type, <attributes-defs> > \<close>
|
|
|
|
\<^item> \<^verbatim>\<open> close_monitor <oid[::class_type],<attributes-updates>> \<close>
|
|
|
|
|
|
|
|
where the automaton of the monitor class is expected
|
|
|
|
to be in a final state.
|
|
|
|
|
|
|
|
Monitors can be nested.
|
|
|
|
|
|
|
|
Classes neither directly or indirectly (via inheritance)
|
|
|
|
mentioned in the monitor clause are \<^emph>\<open>independent\<close> from
|
|
|
|
the monitor and may occur freely, \ie{} in arbitrary order.n \<close>
|
|
|
|
|
|
|
|
|
|
|
|
text \<open>underlying idea: a monitor class automatically receives a
|
|
|
|
\<^verbatim>\<open>trace\<close> attribute in which a list of observed class-ids is maintained.
|
|
|
|
The \<^verbatim>\<open>trace\<close> is a \<^emph>\<open>`predefined id`\<close> like \<^verbatim>\<open>main\<close> in C. It can be accessed
|
|
|
|
like any other attribute of a class instance, \ie{} a document item.\<close>
|
2018-03-21 10:59:27 +00:00
|
|
|
|
2018-04-05 10:09:58 +00:00
|
|
|
doc_class article =
|
2018-04-27 08:34:24 +00:00
|
|
|
style_id :: string <= "''LNCS''"
|
|
|
|
version :: "(int \<times> int \<times> int)" <= "(0,0,0)"
|
2018-11-28 09:49:35 +00:00
|
|
|
accepts "(title ~~
|
|
|
|
\<lbrakk>subtitle\<rbrakk> ~~
|
|
|
|
\<lbrace>author\<rbrace>\<^sup>+ ~~
|
|
|
|
abstract ~~
|
2018-12-03 10:23:51 +00:00
|
|
|
\<lbrace>introduction\<rbrace>\<^sup>+ ~~
|
2018-11-28 09:49:35 +00:00
|
|
|
\<lbrace>technical || example\<rbrace>\<^sup>+ ~~
|
2018-12-03 10:23:51 +00:00
|
|
|
\<lbrace>conclusion\<rbrace>\<^sup>+ ~~
|
2018-12-19 11:05:57 +00:00
|
|
|
bibliography ~~
|
|
|
|
\<lbrace>annex\<rbrace>\<^sup>* )"
|
2018-10-04 14:58:09 +00:00
|
|
|
|
2018-12-18 13:29:08 +00:00
|
|
|
|
|
|
|
ML\<open>
|
|
|
|
structure Scholarly_paper_trace_invariant =
|
|
|
|
struct
|
|
|
|
local
|
|
|
|
|
|
|
|
fun group f g cidS [] = []
|
|
|
|
|group f g cidS (a::S) = case find_first (f a) cidS of
|
|
|
|
NONE => [a] :: group f g cidS S
|
|
|
|
| SOME cid => let val (pref,suff) = take_prefix (g cid) S
|
|
|
|
in (a::pref)::(group f g cidS suff) end;
|
|
|
|
|
|
|
|
fun partition ctxt cidS trace =
|
|
|
|
let fun find_lead (x,_) = DOF_core.is_subclass ctxt x;
|
|
|
|
fun find_cont cid (cid',_) = DOF_core.is_subclass ctxt cid' cid
|
|
|
|
in group find_lead find_cont cidS trace end;
|
|
|
|
|
|
|
|
fun dest_option _ (Const (@{const_name "None"}, _)) = NONE
|
|
|
|
| dest_option f (Const (@{const_name "Some"}, _) $ t) = SOME (f t)
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
fun check ctxt cidS mon_id pos =
|
|
|
|
let val trace = AttributeAccess.compute_trace_ML ctxt mon_id pos @{here}
|
|
|
|
val groups = partition (Context.proof_of ctxt) cidS trace
|
|
|
|
fun get_level_raw oid = AttributeAccess.compute_attr_access ctxt "level" oid @{here} @{here};
|
|
|
|
fun get_level oid = dest_option (snd o HOLogic.dest_number) (get_level_raw (oid));
|
|
|
|
fun check_level_hd a = case (get_level (snd a)) of
|
|
|
|
NONE => error("Invariant violation: leading section" ^ snd a ^
|
|
|
|
" must have lowest level")
|
|
|
|
| SOME X => X
|
|
|
|
fun check_group_elem level_hd a = case (get_level (snd a)) of
|
|
|
|
NONE => true
|
|
|
|
| SOME y => if level_hd <= y then true
|
|
|
|
(* or < ? But this is too strong ... *)
|
|
|
|
else error("Invariant violation: "^
|
|
|
|
"subsequent section " ^ snd a ^
|
|
|
|
" must have higher level.");
|
|
|
|
fun check_group [] = true
|
|
|
|
|check_group [_] = true
|
|
|
|
|check_group (a::S) = forall (check_group_elem (check_level_hd a)) (S)
|
|
|
|
in if forall check_group groups then ()
|
|
|
|
else error"Invariant violation: leading section must have lowest level"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
\<close>
|
|
|
|
|
|
|
|
|
|
|
|
setup\<open> let val cidS = ["scholarly_paper.introduction","scholarly_paper.technical",
|
|
|
|
"scholarly_paper.example", "scholarly_paper.conclusion"];
|
|
|
|
fun body moni_oid _ ctxt = (Scholarly_paper_trace_invariant.check
|
|
|
|
ctxt cidS moni_oid @{here};
|
|
|
|
true)
|
2018-12-19 11:05:57 +00:00
|
|
|
in DOF_core.update_class_invariant "scholarly_paper.article" body end\<close>
|
2018-12-18 13:29:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
(* some test code *)
|
|
|
|
ML\<open>
|
|
|
|
(*
|
|
|
|
|
|
|
|
val trace = AttributeAccess.compute_trace_ML (Context.Proof @{context}) "this" @{here} @{here}
|
|
|
|
val groups = partition ( @{context}) cidS trace
|
|
|
|
val _::_::_::_:: _ ::_ ::_ ::a::_ = groups;
|
|
|
|
check;
|
|
|
|
|
|
|
|
fun get_level_raw oid = AttributeAccess.compute_attr_access (Context.Proof @{context}) "level" oid @{here} @{here};
|
|
|
|
fun get_level oid = dest_option (snd o HOLogic.dest_number) (get_level_raw (oid));
|
|
|
|
fun check_level_hd a = case (get_level (snd a)) of
|
|
|
|
NONE => error("Invariant violation: leading section" ^ snd a ^
|
|
|
|
" must have lowest level")
|
|
|
|
| SOME X => X
|
|
|
|
fun check_group_elem level_hd a = case (get_level (snd a)) of
|
|
|
|
NONE => true
|
|
|
|
| SOME y => if y > level_hd then true
|
|
|
|
else error("Invariant violation: subsequent section " ^ snd a ^
|
|
|
|
" must have higher level.");
|
|
|
|
fun check_group a = map (check_group_elem (check_level_hd (hd a))) (tl a) ;
|
|
|
|
*)
|
|
|
|
\<close>
|
|
|
|
|
|
|
|
|
2018-10-04 13:58:20 +00:00
|
|
|
gen_sty_template
|
2018-10-04 14:58:09 +00:00
|
|
|
|
2018-11-04 17:56:59 +00:00
|
|
|
|
2018-03-21 10:59:27 +00:00
|
|
|
end
|
|
|
|
|