Id = nat;
String = seqofchar|<nil>;
Edition = nat|<nil> inv e == e inset {1,...,50} union {<nil>};
Month = nat|<nil> inv e == e inset {1,...,12} union {<nil>};
Number = nat1|<nil>;
Pages = nat1|<nil>;
Series = nat1|<nil>;
Volume = nat1|<nil>;
Year = nat|<nil> inv e == e inset {1800,...,1998} union {<nil>};
Article::id :Id
author :String
journal :String
month :Month
note :String
number :Number
pages :Pages
title :String
volume :Volume
year :Year;
Book:: id :Id
address :String
author :String
edition :Edition
editor :String
month :Month
note :String
publisher:String
series :Series
title :String
volume :Volume
year :Year;
Inproceeding:: id :Id
address :String
author :String
booktitle:String
editor :String
month :Month
note :String
organization:String
pages :Pages
publisher:String
title :String
year :Year;
Manual::id :Id
address :String
author :String
edition :Edition
month :Month
note :String
organization:String
title :String
year :Year;
Techreport:: id :Id
address :String
author :String
institution:String
month :Month
note :String
number :Number
title :String
type :String
year :Year;
Record = Article | Book | Inproceeding | Manual | Techreport;
state mgd of
dB:setof Record init dB==dB=mk_mgd({}) end
functions
field: Recordtype +> setof Valuetype
field(rt)==
required(rt) union optional(rt) postRESULT=required(rt) union optional(rt);
get: setof Record*Id +> Record
get(dB,i)== let record inset dB in if record.id=i then record else get(dB\{record},i) pre i inset usedIds(dB) postRESULT.id=i andRESULTinset dB measure CardDb;
getvalue: Valuetype*setof Record*Id +> Value
getvalue(valuetype,dB,i)== cases valuetype:
<title> -> get(dB,i).title,
<author> -> get(dB,i).author,
<journal> -> get(dB,i).journal,
<year> -> get(dB,i).year,
<booktitle> -> get(dB,i).booktitle,
<institution> -> get(dB,i).institution,
<publisher> -> get(dB,i).publisher end pre i inset usedIds(dB) and
valuetype inset {<title>,<author>,<journal>,<year>,<booktitle>,
<institution>,<publisher>} post valuetype=<title> andRESULT=get(dB,i).title or
valuetype=<author> andRESULT=get(dB,i).author or
valuetype=<journal> andRESULT=get(dB,i).journal or
valuetype=<year> andRESULT=get(dB,i).year or
valuetype=<booktitle> andRESULT=get(dB,i).booktitle or
valuetype=<institution> andRESULT=get(dB,i).institution or
valuetype=<publisher> andRESULT=get(dB,i).publisher;
iscomplete :setof Record*Id +> bool
iscomplete(dB,i)==
required(recordtype(dB,i))={f|f inset required(recordtype(dB,i))
& not isempty(getvalue(f,dB,i))} pre i inset usedIds(dB) post (forall x inset required(recordtype(dB,i)) & not isempty(getvalue(x,dB,i))) <=> RESULT;
isedition: Value +> bool
isedition(v)==
v inset {1,...,50} or v=<nil>;
isempty: Value +> bool
isempty(value)== if value=<nil> thentrue elsefalse post value=<nil> <=> RESULT;
isidentical: setof Record +> bool
isidentical(dB)== if dB={} thenfalse elselet record1 inset dB in if iscomplete(dB,record1.id) then isidentical2(dB,dB\{record1},dB,record1) else isidentical(dB\{record1}) post (exists i,j inset usedIds(dB) & i<>j and iscomplete(dB,i) and iscomplete (dB,j) and recordtype(dB,i)=recordtype(dB,j) and forall x inset required(recordtype(dB,i))
& getvalue(x,dB,i)=getvalue(x,dB,j)) <=> RESULT;
isidentical2: setof Record*setof Record*setof Record*Record +>bool
isidentical2(dB1,dB2,olddB,record1)== if dB2={} then isidentical(dB1\{record1}) elselet record2 inset dB2 in if iscomplete(olddB,record2.id) then
isidentical3(dB1,dB2,olddB,record1,record2,
required(recordtype(olddB,record1.id))) else isidentical2(dB1,dB2\{record2},olddB,record1);
isidentical3: setof Record*setof Record*setof Record*Record*
Record*setof Valuetype +> bool
isidentical3(dB1,dB2,olddB,record1,record2,requiredfields)== if requiredfields={} thentrue elselet field inset requiredfields in if getvalue(field,olddB,record1.id)<>
getvalue(field,olddB,record2.id) then isidentical2(dB1,dB2\{record2},olddB,record1) else isidentical3(dB1,dB2,olddB,record1,record2,requiredfields\{field});
ismonth: Value +> bool
ismonth(v)==
is_nat(v); --v in set {1,...,12} or v=<nil>;
isnumber: Value +> bool
isnumber(v)==
is_nat(v) or v=<nil>;
ispages: Value +> bool
ispages(v)==
is_nat(v) or v=<nil>;
isstring: Value +> bool
isstring(v)== ifnot is_real(v) thenif v=[] thentrue elseif is_char(hd(v)) then isstring(tl(v)) elsefalse elsefalse;
issubstring: String*String +> bool
issubstring(string1,string2)== if string1=[] thentrue elseif string2=[] or string1=<nil> or string2=<nil> thenfalse elseifhd(string1)=hd(string2) then issubstring2(tl(string1),tl(string2),string1) else issubstring(string1,tl(string2)) post (not (string2=<nil>)) and (exists i,j insetinds(string2)
& substring(string2,i,j)=string1) <=> RESULT;
issubstring2: String*String*String +> bool
issubstring2(string1,string2,oldstring1)== if string1=[] thentrue elseif string2=[] thenfalse elseifhd(string1)=hd(string2) then issubstring2(tl(string1),tl(string2),oldstring1) else issubstring(oldstring1,string2);
isvalueoffield: Value*Valuetype +> bool
isvalueoffield(v,f)== cases f:
<address> -> isstring(v),
<author> -> isstring(v),
<booktitle> -> isstring(v),
<edition> -> isedition(v),
<editor> -> isstring(v),
<institution> ->isstring(v),
<journal> -> isstring(v),
<month> -> ismonth(v),
<note> -> isstring(v),
<number> -> isnumber(v),
<organization> ->isstring(v),
<pages> -> ispages(v),
<publisher> -> isstring(v),
<title> -> isstring(v),
<type> -> isstring(v),
<volume> -> isvolume(v),
<year> -> isyear(v) end post ((f=<address> andexists x:String & x=v) or
(f=<author> andexists x:String & x=v) or
(f=<booktitle> andexists x:String & x=v) or
(f=<edition> andexists x:Edition & x=v) or
(f=<editor> andexists x:String & x=v) or
(f=<institution> andexists x:String & x=v) or
(f=<journal> andexists x:String & x=v) or
(f=<month> andexists x:Month & x=v) or
(f=<note> andexists x:String & x=v) or
(f=<number> andexists x:Number & x=v) or
(f=<organization>andexists x:String & x=v) or
(f=<pages> andexists x:Pages & x=v) or
(f=<publisher> andexists x:String & x=v) or
(f=<title> andexists x:String & x=v) or
(f=<type> andexists x:String & x=v) or
(f=<volume> andexists x:Volume & x=v) or
(f=<year> andexists x:Year & x=v)) <=> RESULT;
isvolume: Value +> bool
isvolume(v)==
is_nat(v) or v=<nil>;
isyear: Value +> bool
isyear(v)==
v inset {1800,...,1998} or v=<nil>;
optional: Recordtype +> setof Valuetype
optional(rt)== cases rt:
<article> -> {<volume>,<number>,<month>,<note>},
<book> -> {<volume>,<series>,<address>,
<edition>,<month>,<note>,<publisher>},
<inproceeding> -> {<editor>,<pages>,<organization>,
<publisher>,<address>,<pages>,<organization>},
<manual> -> {<edition>,<note>,<organization>,<month>,
<address>,<author>,<organization>,<year>},
<techreport> -> {<number>,<note>,<type>,<month>,<address>} end post rt = <article> andRESULT={<volume>,<number>,<month>,<note>} or
rt = <book> andRESULT={<volume>,<series>,<address>,<edition>,<month>,<note>,
<publisher>} or
rt = <inproceeding> andRESULT={<editor>,<pages>,<organization>,<publisher>,<address>,
<pages>,<organization>} or
rt = <manual> andRESULT={<edition>,<note>,<organization>,<month>,<address>,
<author>,<organization>,<year>} or
rt = <techreport> andRESULT={<number>,<note>,<type>,<month>,<address>};
recordtype: setof Record*Id +> Recordtype
recordtype(dB,i)== if is_Article(get(dB,i)) then <article> elseif is_Book(get(dB,i)) then <book> elseif is_Inproceeding(get(dB,i)) then <inproceeding> elseif is_Manual(get(dB,i)) then <manual> else <techreport> pre i inset usedIds(dB) post is_Article(get(dB,i)) andRESULT=<article> or
is_Book(get(dB,i)) andRESULT=<book> or
is_Inproceeding(get(dB,i)) andRESULT=<inproceeding> or
is_Manual(get(dB,i)) andRESULT=<manual> or
is_Techreport(get(dB,i)) andRESULT=<techreport>;
required: Recordtype +> setof Valuetype
required(rt)== cases rt:
<article> -> {<title>,<author>,<journal>,<year>},
<book> -> {<title>,<author>,<publisher>,<year>},
<inproceeding> -> {<title>,<author>,<booktitle>,<year>},
<manual> -> {<title>},
<techreport> -> {<title>,<author>,<institution>,<year>} end post rt = <article> andRESULT={<title>,<author>,<journal>,<year>} or
rt = <book> andRESULT={<title>,<author>,<publisher>,<year>} or
rt = <inproceeding> andRESULT={<title>,<author>,<booktitle>,<year>} or
rt = <manual> andRESULT={<title>} or
rt = <techreport> andRESULT={<title>,<author>,<institution>,<year>};
substring(s:String,i:nat1,j:nat1) r:String pre i<j and j<=len(s) postexists s1,s2:String & len(s1)=i-1 andlen(s2)=len(s)-j and s=s1^r^s2;
usedIds: setof Record +> setof Id
usedIds(dB)==
idset(dB,{}) postforall x inset dB & x.id insetRESULTand forall i insetRESULT & exists x inset dB & x.id = i;
idset: setof Record*setof Id +> setof Id
idset(dB,ids)== if dB={} then ids elselet record inset dB in
idset(dB\{record},ids union {record.id}) measure CardRecords;
CardRecords: setof Record*setof Id +> nat
CardRecords(s,-) == card s;
operations
CREATE: Recordtype ==> Id
CREATE(e)==
(dcl i:nat1:=1;
(while
i inset usedIds(dB) do i:=i+1); cases e:
<article> -> dB:=dB union
{mk_Article(i,<nil>,<nil>,<nil>,<nil>,
<nil>,<nil>,<nil>,<nil>,<nil>)},
<book> -> dB:=dB union
{mk_Book(i,<nil>,<nil>,<nil>,<nil>,
<nil>,<nil>,<nil>,<nil>,<nil>,<nil>,
<nil>)},
<inproceeding> -> dB:=dB union
{mk_Inproceeding(i,<nil>,<nil>,<nil>,
<nil>,<nil>,<nil>,<nil>,<nil>,<nil>,
<nil>,<nil>)},
<manual> -> dB:=dB union
{mk_Manual(i,<nil>,<nil>,<nil>,<nil>,
<nil>,<nil>,<nil>,<nil>)},
<techreport> -> dB:=dB union
{mk_Techreport(i,<nil>,<nil>,<nil>,
<nil>,<nil>,<nil>,<nil>,<nil>,<nil>)} end; return i)
postRESULTnotinset usedIds(dB~) and
e=<article> and
dB=dB~ union {mk_Article(RESULT,<nil>,<nil>,<nil>,<nil>,<nil>,<nil>,
<nil>,<nil>,<nil>)} or e=<book> and
dB=dB~ union {mk_Book(RESULT,<nil>,<nil>,<nil>,<nil>,<nil>,<nil>,
<nil>,<nil>,<nil>,<nil>,<nil>)} or e=<inproceeding> and
dB=dB~ union {mk_Inproceeding(RESULT,<nil>,<nil>,<nil>,<nil>,<nil>,
<nil>,<nil>,<nil>,<nil>,<nil>,<nil>)} or e=<manual> and
dB=dB~ union {mk_Manual(RESULT,<nil>,<nil>,<nil>,<nil>,<nil>,<nil>,
<nil>,<nil>)} or e=<techreport> and
dB=dB~ union {mk_Techreport(RESULT,<nil>,<nil>,<nil>,<nil>,<nil>,
<nil>,<nil>,<nil>,<nil>)};
UPDATE(i:Id,f:Valuetype,v:Value)==
(if i inset usedIds(dB) and f inset field(recordtype(dB,i)) and
isvalueoffield(v,f) then (cases f:
<address> -> let urecord={mu(get(dB,i),address|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<author> -> let urecord={mu(get(dB,i),author|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<booktitle> -> let urecord={mu(get(dB,i),booktitle|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<edition> -> let urecord={mu(get(dB,i),edition|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<editor> -> let urecord={mu(get(dB,i),editor|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<institution> -> let urecord=
{mu(get(dB,i),institution|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<journal> -> let urecord={mu(get(dB,i),journal|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<month> -> let urecord={mu(get(dB,i),month|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<note> -> let urecord={mu(get(dB,i),note|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<number> -> let urecord={mu(get(dB,i),number|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<organization> -> let urecord=
{mu(get(dB,i),organization|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<pages> -> let urecord={mu(get(dB,i),pages|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<publisher> -> let urecord={mu(get(dB,i),publisher|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<title> -> let urecord={mu(get(dB,i),title|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<type> -> let urecord={mu(get(dB,i),type|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<volume> -> let urecord={mu(get(dB,i),volume|->v)} in
dB:=(dB\{get(dB,i)}) union urecord,
<year> -> let urecord={mu(get(dB,i),year|->v)} in
dB:=(dB\{get(dB,i)}) union urecord end; if iscomplete(dB,i) and isidentical(dB) then (DELETE(i); error;))) extwr dB:setof Record pre i inset usedIds(dB) and
f inset field(recordtype(dB,i)) and
isvalueoffield(v,f) and not (iscomplete(dB,i) and isidentical(dB)) post getvalue(f,dB,i)=v and
dB\{get(dB,i)}=dB~\{get(dB~,i)} and forall x inset field(recordtype(dB,i))\{f} &
getvalue(x,dB,i)=getvalue(x,dB~,i);
COMPLETE: Id ==> bool
COMPLETE(i)== return iscomplete(dB,i) pre i inset usedIds(dB) post iscomplete(dB,i) <=> RESULT;
DELETE(i:Id)== if i inset usedIds(dB) then dB:=dB\{get(dB,i)} extwr dB:setof Record pre i inset usedIds(dB) post dB~=dB union {get(dB~,i)};
SEARCH: String ==> setof Id
SEARCH(a)==
(dcl ids:setof Id:={}; forall record inset dB do if issubstring(a,record.author) then ids:=ids union {record.id} else ids:=ids; return ids) postforall i insetRESULT & issubstring(a,get(dB,i).author) andnotexists record inset dB &
(record.id notinsetRESULTand
issubstring(a,get(dB,i).author));
GET: Id ==> Record
GET(i)== return get(dB,i) pre i inset usedIds(dB) postRESULT=get(dB,i);
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.