Skip to content

Commit b2c54fe

Browse files
committed
Small fixes for UVL naming; submission version
1 parent 9f57cb5 commit b2c54fe

File tree

10 files changed

+1874
-416
lines changed

10 files changed

+1874
-416
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# TraVarT Core
1+
# TraVarT Adaptation for Translating Feature Models to UVL and DIMACS
22

3-
This directory contains the core interfaces / classes to be used across the TraVarT Ecosystem.
3+
## Dependencies
4+
* Antlr 3.4 https://www.antlr.org/
5+
* FeatureIDE 3.11.1 https://github.com/FeatureIDE/FeatureIDE/releases/tag/v3.11.1
6+
* UVL Parser 1.0 https://github.com/Universal-Variability-Language/uvl-parser
47

5-
## CheckStyle
68

7-
Configure IntelliJ as follows:
9+
# How to compile
810

9-
1. Install Checkstyle plugin
10-
1. Go to Settings|Editor|Code Style, choose a code style you want to import CheckStyle configuration to.
11-
1. Click Manage...|Import.., choose "CheckStyle Configuration" and select a corresponding CheckStyle configuration file.
12-
Click OK
11+
`mvn clean compile`
1312

14-
[credit](http://biercoff.com/how-to-import-checkstyle-rules-into-intellij-idea-code-format-rules/)
13+
# How to run
14+
`mvn clean compile exec:java -Dexec.args="path/to/models"`

pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@
2828
<groupId>org.pf4j</groupId>
2929
<artifactId>pf4j</artifactId>
3030
<version>3.8.0</version>
31-
<scope>provided</scope>
3231
</dependency>
3332
<dependency>
3433
<groupId>de.vill</groupId>
3534
<artifactId>uvl-parser</artifactId>
3635
<version>1.0-SNAPSHOT</version>
37-
<scope>provided</scope>
3836
</dependency>
3937
<dependency>
4038
<groupId>de.ovgu.featureide</groupId>
4139
<artifactId>lib.fm</artifactId>
42-
<version>3.9.2</version>
40+
<version>3.11.1-2</version>
4341
</dependency>
4442
<dependency>
4543
<groupId>de.ovgu.featureide</groupId>

src/main/java/at/jku/cps/travart/core/ParserMain.java

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.nio.file.Paths;
1414
import java.nio.file.StandardCopyOption;
1515
import java.util.ArrayList;
16+
import java.util.Collection;
1617
import java.util.Comparator;
1718
import java.util.List;
1819
import java.util.Set;
@@ -32,6 +33,7 @@
3233
import at.jku.cps.travart.core.formats.afm.parser.AFMVisitorImpl;
3334
import at.jku.cps.travart.core.formats.afm.parser.AFMParser.Feature_modelContext;
3435
import de.ovgu.featureide.fm.attributes.FMAttributesLibrary;
36+
import de.ovgu.featureide.fm.core.base.IFeature;
3537
import de.ovgu.featureide.fm.core.base.IFeatureModel;
3638
import de.ovgu.featureide.fm.core.base.impl.DefaultFeatureModelFactory;
3739
import de.ovgu.featureide.fm.core.init.FMCoreLibrary;
@@ -55,18 +57,23 @@ public class ParserMain {
5557
private static final String UVL_EXTENSION = "uvl";
5658
private static final String DIMACS_EXTENSION = "dimacs";
5759
private static final String ZIP_EXTENSION = "zip";
60+
private static final String CFR_EXTENSION = "cfr";
61+
62+
private static final Set<String> EXTENSIONS_TO_SKIP = Set.of(
63+
CFR_EXTENSION);
5864

5965
public static void main(String[] args) throws IOException {
6066
FMCoreLibrary.getInstance().install();
6167
FMAttributesLibrary.getInstance().install();
62-
68+
if (args.length != 1) {
69+
System.out.println("Expected number of arguments is 1. Found: " + args.length);
70+
return;
71+
}
6372
PrintStream out = new PrintStream(
6473
new FileOutputStream("log.txt", false), true);
6574
System.setOut(out);
6675
System.setErr(out);
67-
translateFeatureModels();
68-
// filterAfm();
69-
76+
translateFeatureModels(args[0]);
7077
}
7178

7279
private static void deleteDirectoryStream(String path) throws IOException {
@@ -78,8 +85,8 @@ private static void deleteDirectoryStream(String path) throws IOException {
7885
}
7986
}
8087

81-
private static void translateFeatureModels() throws IOException {
82-
String featureModelDir = "../feature-model-benchmark/feature_models/dsads/";
88+
private static void translateFeatureModels(String path) throws IOException {
89+
String featureModelDir = path;
8390

8491
List<File> featureModelFiles = new ArrayList<>();
8592
listf(featureModelDir, featureModelFiles); // Fill list bah
@@ -168,11 +175,16 @@ private static void handleFile(String path, String originalPath, boolean zipResu
168175
return;
169176
}
170177

178+
String extension = getFileExtension(path);
179+
String originalExtension = getFileExtension(originalPath);
180+
181+
if (EXTENSIONS_TO_SKIP.contains(extension)) { // Currently only skips clafer
182+
return;
183+
}
184+
171185
String subPath = originalPath.split("/original/")[1];
172186
String subDirectoryUvlPath = "uvl" + File.separator + subPath.substring(0, subPath.lastIndexOf("/"));
173187
String subDirectoryDimacsPath = "dimacs" + File.separator + subPath.substring(0, subPath.lastIndexOf("/"));
174-
String extension = getFileExtension(path);
175-
String originalExtension = getFileExtension(originalPath);
176188
Files.createDirectories(Paths.get(subDirectoryUvlPath));
177189
Files.createDirectories(Paths.get(subDirectoryDimacsPath));
178190

@@ -198,6 +210,7 @@ private static void handleFile(String path, String originalPath, boolean zipResu
198210
return;
199211
}
200212
}
213+
cleanFeatureIDENamesForUVL(model);
201214
if (!skipUvlExport) {
202215
writeUvlModel(model, uvlPath.replace(".zip", ""));
203216
if (zipResult) {
@@ -292,6 +305,8 @@ private static String getFileExtension(String path) {
292305
return path.substring(lastIndexOf + 1);
293306
}
294307

308+
309+
295310
private static String process(final Tree t, final List<String> ruleNames) {
296311
if (t.getChildCount() == 0)
297312
return Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false);
@@ -344,4 +359,36 @@ private static Set<String> getListOfFilesInDir(String dir) {
344359
.map(File::getPath)
345360
.collect(Collectors.toSet());
346361
}
362+
363+
364+
// ------- Model cleaning
365+
366+
private static void cleanFeatureIDENamesForUVL(IFeatureModel sourceModel) {
367+
Collection<IFeature> iterateCopy = new ArrayList<>();
368+
iterateCopy.addAll(sourceModel.getFeatures());
369+
for (IFeature feat : iterateCopy) {
370+
if (needsRenaming(feat.getName())) {
371+
sourceModel.getRenamingsManager().renameFeature(feat.getName(), getCleanFeatureNameForUVL(feat.getName()));
372+
}
373+
}
374+
}
375+
public static final String[] FORBIDDEN_SYMBOLS = {".", "(", ")", "/", "{", "}", "[", "]", "\"", "'"};
376+
public static final String[] REPLACEMENTS = {":", "-", "-", "-", "-", "-", "-", "-", "-","-"};
377+
378+
private static boolean needsRenaming(String name) {
379+
for (String forbidden : FORBIDDEN_SYMBOLS) {
380+
if (name.contains(forbidden)) {
381+
return true;
382+
}
383+
}
384+
return false;
385+
}
386+
387+
private static String getCleanFeatureNameForUVL(String original) {
388+
String updated = original;
389+
for (int i = 0; i < FORBIDDEN_SYMBOLS.length; i++) {
390+
updated = updated.replace(FORBIDDEN_SYMBOLS[i], REPLACEMENTS[i]);
391+
}
392+
return updated;
393+
}
347394
}

src/main/java/at/jku/cps/travart/core/formats/afm/parser/AFM.g4

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ optional_spec: SPACE? '[' WORD ']' SPACE?;
2424

2525
non_cardinal_spec: (obligatory_spec | optional_spec);
2626

27-
28-
2927
//attributes block
3028

3129
attributes_block: '%Attributes' attribute_spec*;
@@ -50,22 +48,33 @@ value_spec: (WORD | INT | DOUBLE | STRING);
5048

5149
//constraints block
5250

53-
constraints_block: '%Constraints' constraint_spec*;
51+
constraints_block: '%Constraints' constraint_spec*;
5452

5553
constraint_spec: brackets_spec | simple_spec;
5654
brackets_spec:
5755
SPACE? WORD SPACE? '{' SPACE? simple_spec* SPACE? '}' SPACE?;
5856
simple_spec: SPACE? expression SPACE? ';' SPACE?;
5957

6058
expression:
61-
SPACE? '(' SPACE? expression SPACE? ')' SPACE? # parenthesisExp
62-
| SPACE? NOT SPACE? expression # notExp
59+
SPACE? '(' SPACE? expression SPACE? ')' SPACE? # parenthesisExp
60+
| SPACE? NOT SPACE? expression # notExp
6361
| expression SPACE? arithmetic_operator SPACE? expression # arithmeticExp
6462
| expression SPACE? relational_operator SPACE? expression # relationalExp
6563
| expression SPACE? AND SPACE? expression # andExp
6664
| expression SPACE? OR SPACE? expression # orExp
67-
| expression SPACE? logical_operator SPACE? expression # logicalExp
68-
| SPACE? (variable | number) SPACE? # atom;
65+
| expression SPACE? logical_operator SPACE? expression # logicalExp
66+
| SPACE? (variable | number) SPACE? # atom
67+
| error_expression # ERROR;
68+
69+
error_expression: (
70+
logical_operator
71+
| arithmetic_operator
72+
| relational_operator
73+
| number
74+
| variable
75+
| '('
76+
| ')'
77+
)*;
6978

7079
logical_operator: IFF | IMPLIES | REQUIRES | EXCLUDES;
7180
arithmetic_operator: ADD | SUB | MULT | DIV | MOD | POW | ASIG;
@@ -117,7 +126,7 @@ DISTINCT: '!=';
117126

118127
INTEGER: 'Integer';
119128

120-
WORD: [a-zA-Z]([a-z]|[A-Z]|[0-9]|'_')*;
129+
WORD: [a-zA-Z]([a-z] | [A-Z] | [0-9] | '_')*;
121130
INT: '0' | [1-9][0-9]*;
122131
DOUBLE: [1-9][0-9]* '.' [0-9]+;
123132
STRING: '"' (~'"')* '"';

0 commit comments

Comments
 (0)