Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cosyverif
Services
service adt2amas
Commits
a92b47c5
Commit
a92b47c5
authored
Dec 04, 2020
by
Jaime Arias
Browse files
feature: parsing adt2amas GRML file
parent
e27eb603
Changes
4
Hide whitespace changes
Inline
Side-by-side
.classpath
View file @
a92b47c5
...
...
@@ -11,7 +11,7 @@
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
excluding=
"**|target/generated-sources/annotations/
|target/generated-sources/test-annotations/
"
kind=
"src"
output=
"target/classes"
path=
"target"
>
<classpathentry
excluding=
"**|target/generated-sources/annotations/"
kind=
"src"
output=
"target/classes"
path=
"target"
>
<attributes>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
...
...
@@ -33,15 +33,18 @@
<attribute
name=
"maven.pomderived"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"src"
path=
"target/generated-sources/annotations"
>
<classpathentry
kind=
"src"
output=
"target/test-classes"
path=
"target/generated-sources/
test-
annotations"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"test"
value=
"true"
/>
<attribute
name=
"maven.pomderived"
value=
"true"
/>
<attribute
name=
"ignore_optional_problems"
value=
"true"
/>
<attribute
name=
"m2e-apt"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"src"
output=
"target/test-classes"
path=
"target/generated-sources/
test-
annotations"
>
<classpathentry
kind=
"src"
path=
"target/generated-sources/annotations"
>
<attributes>
<attribute
name=
"optional"
value=
"true"
/>
<attribute
name=
"test"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"output"
path=
"target/classes"
/>
...
...
README.md
View file @
a92b47c5
...
...
@@ -18,8 +18,9 @@ You can use the
[
Alligator
](
https://depot.lipn.univ-paris13.fr/cosyverif/alligator/alligator
)
Docker image as development environment.
To run tests you can use the tool
[
soapui
](
https://www.soapui.org/
)
. An
example is shown below:
To run tests you can use the tool
[
soapui
](
https://www.soapui.org/
)
. The
initial WSDL is http://localhost:9000/services?wsdl. An example is shown
below:
```
xml
...
...
src/main/java/org/cosyverif/service/adt2amas/GrmlParser.java
View file @
a92b47c5
...
...
@@ -4,7 +4,12 @@ import java.io.BufferedWriter;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.ArrayDeque
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Queue
;
import
lombok.AccessLevel
;
import
lombok.Getter
;
...
...
@@ -16,6 +21,7 @@ import lombok.experimental.Accessors;
import
org.cosyverif.Configuration
;
import
org.cosyverif.model.Model
;
import
org.cosyverif.model.Node
;
import
org.cosyverif.model.Arc
;
import
org.cosyverif.model.Attribute
;
@Getter
(
AccessLevel
.
PUBLIC
)
...
...
@@ -25,7 +31,7 @@ import org.cosyverif.model.Attribute;
public
class
GrmlParser
{
private
Model
model
;
private
Map
<
String
,
ADTreeNode
>
mapNodes
=
new
HashMap
<
String
,
ADTreeNode
>();
private
Hash
Map
<
String
,
ADTreeNode
>
mapNodes
=
new
HashMap
<
String
,
ADTreeNode
>();
private
GrmlParser
(
Model
model
)
{
this
.
model
=
model
;
...
...
@@ -46,28 +52,86 @@ public class GrmlParser {
fw
=
new
FileWriter
(
fileOutput
);
bw
=
new
BufferedWriter
(
fw
);
/* parsing */
/** Parsing root node */
String
root
=
""
;
for
(
Attribute
attr
:
model
.
getAttribute
())
{
if
(
attr
.
getName
().
equals
(
"root"
)
&&
attr
.
getContent
().
size
()
==
1
)
{
root
=
(
String
)
attr
.
getContent
().
get
(
0
);
}
}
/* parsing nodes */
for
(
Node
node
:
model
.
getNode
())
{
bw
.
write
(
"Type: "
);
bw
.
write
(
node
.
getNodeType
());
bw
.
newLine
();
HashMap
<
String
,
String
>
attrs
=
new
HashMap
<
String
,
String
>();
String
id
=
node
.
getId
().
toString
();
// default values of attributes
attrs
.
put
(
"time"
,
"0"
);
attrs
.
put
(
"cost"
,
"0"
);
ADTreeNode
adtreeNode
=
new
ADTreeNode
(
node
.
getId
().
toString
());
attrs
.
put
(
"type"
,
node
.
getNodeType
());
// Parse attributes
for
(
Object
content
:
node
.
getNodeContent
())
{
if
(
content
instanceof
Attribute
)
{
val
attr
=
Attribute
.
class
.
cast
(
content
);
bw
.
write
(
"name: "
);
bw
.
write
(
attr
.
getName
());
bw
.
newLine
();
// bw.write(attr.getContent().toString());
String
attributeName
=
attr
.
getName
();
List
<
Object
>
attributeContent
=
attr
.
getContent
();
if
(
attributeContent
.
size
()
==
0
)
{
throw
new
Exception
(
"Empty Attribute"
);
}
else
if
(
attributeContent
.
size
()
==
1
)
{
String
value
=
(
String
)
attributeContent
.
get
(
0
);
attrs
.
put
(
attributeName
,
value
);
}
else
if
(
attributeName
.
equals
(
"attributes"
))
{
attrs
.
putAll
(
getAttributes
(
attr
));
}
}
}
bw
.
newLine
();
bw
.
newLine
();
// create ADTree Node
ADTreeNode
adtreeNode
=
new
ADTreeNode
(
id
,
attrs
.
get
(
"type"
).
toLowerCase
(),
attrs
.
get
(
"name"
).
replaceAll
(
"\\s+"
,
"_"
),
attrs
.
get
(
"role"
).
toLowerCase
(),
attrs
.
get
(
"time"
),
attrs
.
get
(
"cost"
),
new
ArrayList
<
String
>());
mapNodes
.
put
(
id
,
adtreeNode
);
}
/* parsing arcs */
for
(
Arc
arc
:
model
.
getArc
())
{
if
(
arc
.
getArcType
().
equals
(
"arc"
))
{
String
source
=
arc
.
getSource
().
toString
();
String
target
=
arc
.
getTarget
().
toString
();
mapNodes
.
get
(
source
).
addChild
(
target
);
}
}
/** Create ADT2AMAS input file */
bw
.
write
(
mapNodes
.
get
(
root
).
name
()
+
"\n"
);
for
(
Map
.
Entry
element
:
mapNodes
.
entrySet
())
{
ADTreeNode
node
=
(
ADTreeNode
)
element
.
getValue
();
bw
.
write
(
"\n"
+
node
.
name
()
+
" "
+
node
.
type
()
+
" "
+
node
.
role
()
+
" "
+
node
.
cost
()
+
" "
+
node
.
time
());
}
}
catch
(
IOException
e
)
{
bw
.
newLine
();
Queue
<
String
>
queue
=
new
ArrayDeque
<
String
>();
queue
.
add
(
root
);
while
(!
queue
.
isEmpty
())
{
String
node
=
queue
.
remove
();
ArrayList
<
String
>
children
=
mapNodes
.
get
(
node
).
chidlren
();
if
(!
children
.
isEmpty
())
{
queue
.
addAll
(
children
);
bw
.
write
(
"\n"
+
mapNodes
.
get
(
node
).
name
());
for
(
String
child
:
children
)
{
bw
.
write
(
" "
+
mapNodes
.
get
(
child
).
name
());
}
}
}
bw
.
write
(
"\n\n"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
bw
!=
null
)
bw
.
close
();
...
...
@@ -76,29 +140,77 @@ public class GrmlParser {
return
fileOutput
;
}
private
HashMap
<
String
,
String
>
getAttributes
(
Attribute
node
)
{
HashMap
<
String
,
String
>
attrs
=
new
HashMap
<
String
,
String
>();
// Group of attributes
for
(
Object
object
:
node
.
getContent
())
{
if
(
object
instanceof
Attribute
)
{
val
attribute
=
Attribute
.
class
.
cast
(
object
);
List
<
Object
>
attributeContent
=
attribute
.
getContent
();
// it's a valid ADTree attribute
if
(
attribute
.
getName
().
equals
(
"attribute"
))
{
HashMap
<
String
,
String
>
tmp
=
new
HashMap
<
String
,
String
>();
for
(
Object
attrObject
:
attributeContent
)
{
if
(
attrObject
instanceof
Attribute
)
{
val
attrInfo
=
Attribute
.
class
.
cast
(
attrObject
);
List
<
Object
>
attrContent
=
attrInfo
.
getContent
();
// well-formed attribute
if
(
attrContent
.
size
()
==
1
)
{
tmp
.
put
(
attrInfo
.
getName
(),
(
String
)
attrContent
.
get
(
0
));
}
}
}
// save attribute
if
(
tmp
.
containsKey
(
"name"
)
&&
tmp
.
containsKey
(
"value"
))
{
attrs
.
put
(
tmp
.
get
(
"name"
),
tmp
.
get
(
"value"
));
}
}
}
}
return
attrs
;
}
}
@AllArgsConstructor
@Getter
(
AccessLevel
.
PUBLIC
)
@Setter
(
AccessLevel
.
PUBLIC
)
@Accessors
(
chain
=
true
,
fluent
=
true
)
fluent
=
true
)
class
ADTreeNode
{
/** Identifier of the node */
private
in
t
id
;
private
Str
in
g
id
;
/** Type of the node */
private
String
type
;
/** Name of the node */
private
String
name
=
""
;
private
String
name
;
/** Role of the node */
private
String
role
=
"ATTACK"
;
private
String
role
;
/**
Cost
attribute of the node */
private
double
time
=
0
;
/**
Time
attribute of the node */
private
String
time
;
/** Cost attribute of the node */
private
double
cost
=
0
;
private
String
cost
;
/** Children of the node */
private
ArrayList
<
String
>
chidlren
;
/**
* Add a new child to the node
*
* @param child new child
*/
public
void
addChild
(
String
child
)
{
this
.
chidlren
.
add
(
child
);
}
}
src/main/resources/treasure_hunters.txt
0 → 100644
View file @
a92b47c5
TS
b leaf attack 500 60
f leaf attack 100 120
h leaf attack 500 3
e leaf attack 0 10
p leaf defence 100 10
GA or attack 0 0
ST and attack 0 2
TF sand attack 0 0
TS nand attack 0 0
TS TF p
TF ST GA
ST b f
GA h e
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