aboutsummaryrefslogtreecommitdiffstats
path: root/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend')
-rw-r--r--Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend170
1 files changed, 170 insertions, 0 deletions
diff --git a/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend
new file mode 100644
index 00000000..f9086683
--- /dev/null
+++ b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend
@@ -0,0 +1,170 @@
1package hu.bme.mit.inf.dslreasoner.run
2
3import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage
4import hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.Mutated
5import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace
6import java.io.File
7import java.util.ArrayList
8import java.util.Collection
9import java.util.Comparator
10import java.util.HashMap
11import java.util.List
12import java.util.Map
13import java.util.TreeSet
14import org.eclipse.emf.ecore.EObject
15import org.eclipse.emf.ecore.resource.Resource
16import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl
17import org.eclipse.viatra.query.runtime.api.IPatternMatch
18import org.eclipse.viatra.query.runtime.api.IQuerySpecification
19import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine
20import org.eclipse.viatra.query.runtime.emf.EMFScope
21
22class QueryComparator implements Comparator<IQuerySpecification<?>>{
23
24 override compare(IQuerySpecification<?> arg0, IQuerySpecification<?> arg1) {
25 arg0.fullyQualifiedName.compareTo(arg1.fullyQualifiedName)
26 }
27}
28
29class CountMatches {
30 var static List<IQuerySpecification<?>> wfPatterns;
31 var static Map<IQuerySpecification<?>,IQuerySpecification<?>> query2Reference
32
33 def static void main(String[] args) {
34 YakindummPackage.eINSTANCE.eClass
35 Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("*",new XMIResourceFactoryImpl)
36
37 wfPatterns = Mutated.instance.specifications.toList;
38 //wfPatterns = wfPatterns.filter[it.allAnnotations.exists[it.name == "Constraint"]].toList
39 wfPatterns.sort(new QueryComparator)
40
41 val groupName2Representant = new HashMap
42 query2Reference = new HashMap
43 for(wfPattern : wfPatterns) {
44 val groupName = wfPattern.groupName
45 if(groupName2Representant.containsKey(groupName)) {
46 val representant = groupName2Representant.get(groupName)
47 query2Reference.put(wfPattern,representant)
48 } else {
49 groupName2Representant.put(groupName,wfPattern)
50 }
51 }
52
53
54 println('''modelpath;run;model;«
55 FOR wfPattern:wfPatterns SEPARATOR ";"»#(«
56 wfPattern.fullyQualifiedName.split("\\.").last»);hash(«
57 wfPattern.fullyQualifiedName.split("\\.").last»)«ENDFOR»;«
58 FOR mutant : wfPatterns.filter[query2Reference.keySet.contains(it)] SEPARATOR ';'»diff(«
59 mutant.fullyQualifiedName.split("\\.").last»)«ENDFOR»'''
60 )
61 countMatches('''D:/FASE18Meas/MetamodelOnly_Alloy_Symmetry30''')
62 }
63
64 def private static simpleName(IQuerySpecification<?> wfPattern) {
65 wfPattern.fullyQualifiedName.split("\\.").last
66 }
67 def private static groupName(IQuerySpecification<?> wfPattern) {
68 wfPattern.simpleName.split('_').head
69 }
70
71 def static void countMatches(String path) {
72 val file = new File(path)
73 if(file.isDirectory) {
74 for(subFileName : file.list) {
75 (path + "/" + subFileName).countMatches
76 }
77 } else if(file.isFile) {
78 if(path.endsWith("xmi")) {
79 countMatches(file,path)
80 }
81 }
82 }
83
84 def static void countMatches(File file, String path) {
85 val parent = file.parent
86
87 val pathSegments = path.split("/")
88 val groupName = pathSegments.get(pathSegments.size-2).split("\\.").last.split("_").get(0)
89 print(groupName +";")
90 val nameExtension = pathSegments.get(pathSegments.size-1).split("\\.").get(0).split("_")
91 val runNumber = nameExtension.get(1)
92 val modelNumber = nameExtension.get(2)
93 print('''«runNumber»;«modelNumber»''')
94 val workspace = new FileSystemWorkspace(parent,"")
95 val model = workspace.readModel(EObject,file.name)
96
97 val engine = ViatraQueryEngine.on(new EMFScope(model))
98 val objectCode = model.eResource.calculateObjectCode
99
100 val pattern2Hash = new HashMap
101 for(pattern : wfPatterns) {
102 val matcher = pattern.getMatcher(engine)
103 val matches = matcher.allMatches
104 val hash = matches.getMatchSetDescriptor(objectCode)
105 pattern2Hash.put(pattern,hash)
106 print(''';«matcher.countMatches»;«hash»''')
107 }
108 var mutantsKilled = 0
109 for(mutant : wfPatterns.filter[query2Reference.keySet.contains(it)]) {
110 val equals = pattern2Hash.get(mutant) == pattern2Hash.get(query2Reference.get(mutant))
111 print(''';''')
112 if(equals) {
113 print('0')
114 } else {
115 print('1')
116 mutantsKilled++
117 }
118 }
119 //print(''';«mutantsKilled»''')
120 println()
121 }
122
123 def static Map<EObject,Integer> calculateObjectCode(Resource resource) {
124 val res = new HashMap
125 val iterator = resource.allContents
126 var index = 1
127 while(iterator.hasNext) {
128 res.put(iterator.next,index++)
129 }
130 return res
131 }
132
133 def static getMatchSetDescriptor(Collection<? extends IPatternMatch> matchSet, Map<EObject,Integer> objectCode) {
134 val set = new TreeSet(new ArrayComparator)
135 for(match: matchSet) {
136 val size = match.parameterNames.size
137 val idArray = new ArrayList<Integer>(size)
138 for(i:0..<size) {
139 val objectInMatch = match.get(i)
140 if(objectInMatch instanceof EObject) {
141 val id = objectCode.get(objectInMatch)
142 if(id!== null) {
143 idArray+= id
144 } else {
145 throw new IllegalArgumentException('''Unindexed object in match: «objectInMatch»''')
146 }
147 } else {
148 throw new IllegalArgumentException('''Unknown type object in match: "«objectInMatch.class.simpleName»"''')
149 }
150 }
151 set += idArray
152 }
153 return '''«FOR match : set SEPARATOR ','»[«FOR index : match SEPARATOR ','»«index»«ENDFOR»]«ENDFOR»'''.toString.hashCode
154 }
155}
156
157class ArrayComparator implements Comparator<List<Integer>> {
158
159 override compare(List<Integer> arg0, List<Integer> arg1) {
160 if(arg0.size === arg1.size) {
161 for(i : 0..<arg0.size) {
162 val comparison = arg0.get(i).compareTo(arg1.get(i))
163 if(comparison !== 0) return comparison
164 }
165 return 0
166 } else {
167 throw new IllegalArgumentException('''the arrays need to be in the same size''')
168 }
169 }
170} \ No newline at end of file