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.xtend176
1 files changed, 0 insertions, 176 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
deleted file mode 100644
index 02caf9dd..00000000
--- a/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/CountMatches.xtend
+++ /dev/null
@@ -1,176 +0,0 @@
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/RemoHF''')
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
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 try{
92 val runNumber = nameExtension.get(1)
93 val modelNumber = nameExtension.get(2)
94 print('''«runNumber»;«modelNumber»''')
95 } catch(Exception e) {
96 print('''«file.name»;0''')
97 }
98
99 val parent = file.parent
100 val workspace = new FileSystemWorkspace(parent,"")
101 val model = workspace.readModel(EObject,file.name)
102
103 val engine = ViatraQueryEngine.on(new EMFScope(model))
104 val objectCode = model.eResource.calculateObjectCode
105
106 val pattern2Hash = new HashMap
107 for(pattern : wfPatterns) {
108 val matcher = pattern.getMatcher(engine)
109 val matches = matcher.allMatches
110 val hash = matches.getMatchSetDescriptor(objectCode)
111 pattern2Hash.put(pattern,hash)
112 print(''';«matcher.countMatches»;«hash»''')
113 }
114 var mutantsKilled = 0
115 for(mutant : wfPatterns.filter[query2Reference.keySet.contains(it)]) {
116 val equals = pattern2Hash.get(mutant) == pattern2Hash.get(query2Reference.get(mutant))
117 print(''';''')
118 if(equals) {
119 print('0')
120 } else {
121 print('1')
122 mutantsKilled++
123 }
124 }
125 //print(''';«mutantsKilled»''')
126 println()
127 }
128
129 def static Map<EObject,Integer> calculateObjectCode(Resource resource) {
130 val res = new HashMap
131 val iterator = resource.allContents
132 var index = 1
133 while(iterator.hasNext) {
134 res.put(iterator.next,index++)
135 }
136 return res
137 }
138
139 def static getMatchSetDescriptor(Collection<? extends IPatternMatch> matchSet, Map<EObject,Integer> objectCode) {
140 val set = new TreeSet(new ArrayComparator)
141 for(match: matchSet) {
142 val size = match.parameterNames.size
143 val idArray = new ArrayList<Integer>(size)
144 for(i:0..<size) {
145 val objectInMatch = match.get(i)
146 if(objectInMatch instanceof EObject) {
147 val id = objectCode.get(objectInMatch)
148 if(id!== null) {
149 idArray+= id
150 } else {
151 throw new IllegalArgumentException('''Unindexed object in match: «objectInMatch»''')
152 }
153 } else {
154 throw new IllegalArgumentException('''Unknown type object in match: "«objectInMatch.class.simpleName»"''')
155 }
156 }
157 set += idArray
158 }
159 return '''«FOR match : set SEPARATOR ','»[«FOR index : match SEPARATOR ','»«index»«ENDFOR»]«ENDFOR»'''.toString.hashCode
160 }
161}
162
163class ArrayComparator implements Comparator<List<Integer>> {
164
165 override compare(List<Integer> arg0, List<Integer> arg1) {
166 if(arg0.size === arg1.size) {
167 for(i : 0..<arg0.size) {
168 val comparison = arg0.get(i).compareTo(arg1.get(i))
169 if(comparison !== 0) return comparison
170 }
171 return 0
172 } else {
173 throw new IllegalArgumentException('''the arrays need to be in the same size''')
174 }
175 }
176} \ No newline at end of file