Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
ProofScriptParser
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
24
Issues
24
List
Boards
Labels
Service Desk
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sarah.grebing
ProofScriptParser
Commits
d6247320
Commit
d6247320
authored
Aug 20, 2017
by
Sarah Grebing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Matching of Semisequents interimstate
parent
cc20826f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
49 deletions
+93
-49
src/main/java/edu/kit/formal/psdb/termmatcher/MatcherFacade.java
...n/java/edu/kit/formal/psdb/termmatcher/MatcherFacade.java
+38
-27
src/main/java/edu/kit/formal/psdb/termmatcher/MatcherImpl.java
...ain/java/edu/kit/formal/psdb/termmatcher/MatcherImpl.java
+47
-14
src/test/java/edu/kit/formal/psdb/termmatcher/MatcherFacadeTest.java
...va/edu/kit/formal/psdb/termmatcher/MatcherFacadeTest.java
+8
-8
No files found.
src/main/java/edu/kit/formal/psdb/termmatcher/MatcherFacade.java
View file @
d6247320
...
...
@@ -4,13 +4,22 @@ import de.uka.ilkd.key.logic.Semisequent;
import
de.uka.ilkd.key.logic.Sequent
;
import
de.uka.ilkd.key.logic.SequentFormula
;
import
de.uka.ilkd.key.logic.Term
;
import
edu.kit.formal.psdb.termmatcher.MatchPatternParser.SemiSeqPatternContext
;
import
org.antlr.v4.runtime.CharStream
;
import
org.antlr.v4.runtime.CharStreams
;
import
org.antlr.v4.runtime.CommonTokenStream
;
import
org.key_project.util.collection.ImmutableList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
static
edu
.
kit
.
formal
.
psdb
.
termmatcher
.
MatchPatternParser
.
SequentPatternContext
;
import
static
edu
.
kit
.
formal
.
psdb
.
termmatcher
.
MatchPatternParser
.
TermPatternContext
;
import
static
edu
.
kit
.
formal
.
psdb
.
termmatcher
.
MatcherImpl
.
MatchInfo
;
import
static
edu
.
kit
.
formal
.
psdb
.
termmatcher
.
MatcherImpl
.
NO_MATCH
;
/**
* A facade for capturing everthing we want to do with matchers.
...
...
@@ -22,7 +31,7 @@ public class MatcherFacade {
public
static
Matchings
matches
(
String
pattern
,
Term
keyTerm
)
{
MatcherImpl
matcher
=
new
MatcherImpl
();
MatchPatternParser
mpp
=
getParser
(
pattern
);
MatchPatternParser
.
TermPatternContext
ctx
=
mpp
.
termPattern
();
TermPatternContext
ctx
=
mpp
.
termPattern
();
return
matcher
.
accept
(
ctx
,
keyTerm
);
}
...
...
@@ -50,64 +59,66 @@ public class MatcherFacade {
public
static
Matchings
matches
(
String
pattern
,
Semisequent
semiSeq
)
{
MatchPatternParser
mpp
=
getParser
(
pattern
);
MatchPatternParser
.
SemiSeqPatternContext
ctx
=
mpp
.
semiSeqPattern
();
SemiSeqPatternContext
ctx
=
mpp
.
semiSeqPattern
();
return
matches
(
ctx
,
semiSeq
);
}
public
static
Matchings
matches
(
MatchPatternParser
.
SemiSeqPatternContext
pattern
,
Semisequent
semiSeq
)
{
public
static
Matchings
matches
(
SemiSeqPatternContext
pattern
,
Semisequent
semiSeq
)
{
MatcherImpl
matcher
=
new
MatcherImpl
();
ImmutableList
<
SequentFormula
>
allSequentFormulas
=
semiSeq
.
asList
();
List
<
MatchPatternParser
.
TermPatternContext
>
termPatternContexts
=
pattern
.
termPattern
();
List
<
TermPatternContext
>
termPatternContexts
=
pattern
.
termPattern
();
List
<
Matchings
>
allMatches
=
new
ArrayList
<>();
List
<
List
<
MatcherImpl
.
MatchInfo
>
>
allMatches
=
new
ArrayList
<>();
for
(
MatchPatternParser
.
TermPatternContext
termPatternContext
:
termPatternContexts
)
{
Matchings
m
=
new
Matchings
();
for
(
TermPatternContext
termPatternContext
:
termPatternContexts
)
{
List
<
MatchInfo
>
m
=
new
ArrayList
<>
();
for
(
SequentFormula
form
:
allSequentFormulas
)
{
Matchings
temp
=
matcher
.
accept
(
termPatternContext
,
form
.
formula
());
m
.
addAll
(
temp
);
for
(
HashMap
<
String
,
Term
>
match
:
temp
)
{
m
.
add
(
new
MatchInfo
(
match
,
Collections
.
singleton
(
form
)));
}
}
allMatches
.
add
(
m
);
}
Matchings
res
=
reduceCompatibleMatches
(
allMatches
);
List
<
MatchInfo
>
res
=
reduceCompatibleMatches
(
allMatches
);
System
.
out
.
println
(
"res = "
+
res
);
return
res
;
if
(
res
==
null
)
return
NO_MATCH
;
List
<
HashMap
<
String
,
Term
>>
resMap
=
res
.
stream
().
map
(
el
->
el
.
matching
).
collect
(
Collectors
.
toList
());
Matchings
resMatchings
=
new
Matchings
();
resMatchings
.
addAll
(
resMap
);
return
resMatchings
;
}
//BiMap<Pair<SequentFormula, MatchPatternParser.TermPatternContext>, Matchings> formulaToMatchingInfo,
/**
* Reduce all matches to only comaptible matchings
* @param allMatches
* @return
*/
private
static
Matchings
reduceCompatibleMatches
(
List
<
Matchings
>
allMatches
)
{
private
static
List
<
MatchInfo
>
reduceCompatibleMatches
(
List
<
List
<
MatchInfo
>
>
allMatches
)
{
if
(
allMatches
.
size
()
==
2
)
{
return
MatcherImpl
.
reduceConform
(
allMatches
.
get
(
0
),
allMatches
.
get
(
1
));
}
else
{
Matchings
tmp
=
MatcherImpl
.
reduceConform
(
allMatches
.
get
(
0
),
allMatches
.
get
(
1
));
List
<
Matchings
>
list
=
new
ArrayList
<>();
List
<
MatchInfo
>
tmp
=
MatcherImpl
.
reduceConform
(
allMatches
.
get
(
0
),
allMatches
.
get
(
1
));
List
<
List
<
MatchInfo
>
>
list
=
new
ArrayList
<>();
list
.
add
(
tmp
);
list
.
addAll
(
allMatches
.
subList
(
2
,
allMatches
.
size
()));
return
reduceCompatibleMatches
(
list
);
}
}
/**
* Filter matchings s.t. only those remain, that fit the pattern
*
* @param allCompatibelMatchings
* @param pattern
* @return
*/
private
static
List
<
Matchings
>
filterMatchings
(
List
<
Matchings
>
allCompatibelMatchings
,
MatchPatternParser
.
SemiSeqPatternContext
pattern
)
{
List
<
Matchings
>
ret
=
new
ArrayList
<>();
List
<
MatchPatternParser
.
TermPatternContext
>
termPatternContexts
=
pattern
.
termPattern
();
return
ret
;
}
/**
* Match a sequent pattern against a concrete sequent
...
...
@@ -119,7 +130,7 @@ public class MatcherFacade {
public
static
Matchings
matches
(
String
pattern
,
Sequent
sequent
)
{
MatcherImpl
matcher
=
new
MatcherImpl
();
MatchPatternParser
mpp
=
getParser
(
pattern
);
MatchPatternParser
.
SequentPatternContext
ctx
=
mpp
.
sequentPattern
();
SequentPatternContext
ctx
=
mpp
.
sequentPattern
();
Semisequent
antec
=
sequent
.
antecedent
();
Semisequent
succ
=
sequent
.
succedent
();
...
...
src/main/java/edu/kit/formal/psdb/termmatcher/MatcherImpl.java
View file @
d6247320
package
edu.kit.formal.psdb.termmatcher
;
import
de.uka.ilkd.key.logic.SequentFormula
;
import
de.uka.ilkd.key.logic.Term
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Stack
;
import
java.util.*
;
import
java.util.stream.IntStream
;
import
java.util.stream.Stream
;
...
...
@@ -19,6 +18,41 @@ class MatcherImpl extends MatchPatternDualVisitor<Matchings, Term> {
private
Stack
<
Term
>
termStack
=
new
Stack
<>();
protected
static
List
<
MatchInfo
>
reduceConform
(
List
<
MatchInfo
>
m1
,
List
<
MatchInfo
>
m2
)
{
if
(
m1
==
null
||
m2
==
null
)
return
null
;
//"null" is equivalent to NO_MATCH
List
<
MatchInfo
>
res
=
new
ArrayList
<>();
boolean
oneMatch
=
false
;
for
(
MatchInfo
minfo1
:
m1
)
{
for
(
MatchInfo
minfo2
:
m2
)
{
Set
<
SequentFormula
>
intersection
=
new
HashSet
<>(
minfo1
.
matchedForms
);
intersection
.
retainAll
(
minfo2
.
matchedForms
);
if
(!
intersection
.
isEmpty
())
continue
;
HashMap
<
String
,
Term
>
h3
=
reduceConform
(
minfo1
.
matching
,
minfo2
.
matching
);
if
(
h3
!=
null
)
{
Set
<
SequentFormula
>
union
=
new
HashSet
<>(
minfo1
.
matchedForms
);
union
.
addAll
(
minfo2
.
matchedForms
);
res
.
add
(
new
MatchInfo
(
h3
,
union
));
oneMatch
=
true
;
}
}
}
return
oneMatch
?
res
:
null
;
}
private
static
HashMap
<
String
,
Term
>
reduceConform
(
HashMap
<
String
,
Term
>
h1
,
HashMap
<
String
,
Term
>
h2
)
{
HashMap
<
String
,
Term
>
h3
=
new
HashMap
<>(
h1
);
for
(
String
s1
:
h3
.
keySet
())
{
if
(
h2
.
containsKey
(
s1
)
&&
!
h2
.
get
(
s1
).
equals
(
h1
.
get
(
s1
)))
{
return
null
;
}
}
h3
.
putAll
(
h2
);
return
h3
;
}
/**
* Reduce the matchings by eliminating non-compatible matchings.
* For example:
...
...
@@ -53,17 +87,6 @@ class MatcherImpl extends MatchPatternDualVisitor<Matchings, Term> {
}
}*/
private
static
HashMap
<
String
,
Term
>
reduceConform
(
HashMap
<
String
,
Term
>
h1
,
HashMap
<
String
,
Term
>
h2
)
{
HashMap
<
String
,
Term
>
h3
=
new
HashMap
<>(
h1
);
for
(
String
s1
:
h3
.
keySet
())
{
if
(
h2
.
containsKey
(
s1
)
&&
!
h2
.
get
(
s1
).
equals
(
h1
.
get
(
s1
)))
{
return
null
;
}
}
h3
.
putAll
(
h2
);
return
h3
;
}
/**
* Visit '_'
*
...
...
@@ -173,6 +196,16 @@ class MatcherImpl extends MatchPatternDualVisitor<Matchings, Term> {
subTerms
(
list
,
s
);
}
}
public
static
class
MatchInfo
{
public
HashMap
<
String
,
Term
>
matching
;
public
Set
<
SequentFormula
>
matchedForms
;
public
MatchInfo
(
HashMap
<
String
,
Term
>
m
,
Set
<
SequentFormula
>
f
)
{
matching
=
m
;
matchedForms
=
f
;
}
}
}
/**
...
...
src/test/java/edu/kit/formal/psdb/termmatcher/MatcherFacadeTest.java
View file @
d6247320
...
...
@@ -42,8 +42,8 @@ public class MatcherFacadeTest {
shouldMatch
(
"f(a)"
,
"f(a)"
);
shouldMatchForm
(
"pred(a)"
,
"_"
);
shouldMatchForm
(
"pred(a)"
,
"pred(?X)"
,
"[{?X=a}]"
);
shouldMatchSemiSeq
(
"pred(a), pred(b) ==>"
,
"pred(?X), pred(?Y)"
);
shouldMatchSemiSeq
(
"pred(a), pred(b) ==>"
,
"pred(?X), pred(?X)"
,
"[
{?X=a}, {?X=b}
]"
);
shouldMatchSemiSeq
(
"pred(a), pred(b) ==>"
,
"pred(?X), pred(?Y)"
,
"[{?X=a, ?Y=b}, {?X=b, ?Y=a}]"
);
shouldMatchSemiSeq
(
"pred(a), pred(b) ==>"
,
"pred(?X), pred(?X)"
,
"[]"
);
shouldMatchSemiSeq
(
"pred(a), pred(f(a)) ==>"
,
"pred(?X), pred(f(?X))"
,
"[{?X=a}]"
);
shouldMatchSemiSeq
(
"pred(b), pred(f(a)) ==>"
,
"pred(?X), pred(f(?X))"
,
"[]"
);
// shouldMatchSemiSeq("pred(a), pred(b) ==> qpred(a,b)", "pred(a), pred(b)");
...
...
@@ -85,12 +85,6 @@ public class MatcherFacadeTest {
Assert
.
assertEquals
(
exp
,
m
.
toString
());
}
private
void
shouldMatchSemiSeq
(
String
s
,
String
s1
)
throws
ParserException
{
Sequent
term
=
parseSeq
(
s
);
Matchings
m
=
MatcherFacade
.
matches
(
s1
,
term
);
System
.
out
.
println
(
m
);
}
private
void
shouldMatchSemiSeq
(
String
s
,
String
s1
,
String
exp
)
throws
ParserException
{
Sequent
term
=
parseSeq
(
s
);
Matchings
m
=
MatcherFacade
.
matches
(
s1
,
term
);
...
...
@@ -133,4 +127,10 @@ public class MatcherFacadeTest {
Reader
in
=
new
StringReader
(
s
);
return
dtp
.
parseSeq
(
in
,
services
,
namespace
,
abbrev
);
}
private
void
shouldMatchSemiSeq
(
String
s
,
String
s1
)
throws
ParserException
{
Sequent
term
=
parseSeq
(
s
);
Matchings
m
=
MatcherFacade
.
matches
(
s1
,
term
);
System
.
out
.
println
(
m
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment