Aufgrund einer Wartung wird GitLab am 26.10. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 26.10. between 8:00 and 9:00 am.

Commit b3e98367 authored by Abdallah Atouani's avatar Abdallah Atouani
Browse files

add DatasetArtifact tag and change package structure

parent f98831c6
Pipeline #403501 passed with stage
in 1 minute and 30 seconds
package de.monticore.lang.monticar.emadl.tagging.artifacttag;
import de.monticore.lang.tagging._symboltable.TagKind;
import de.monticore.lang.tagging._symboltable.TagSymbol;
public class DatasetArtifactSymbol extends TagSymbol {
public static final DatasetArtifactKind KIND = DatasetArtifactKind.INSTANCE;
public DatasetArtifactSymbol() {
super(KIND, ".");
}
public DatasetArtifactSymbol(String artifact, String jar, String id) {
this(KIND, artifact, jar, id);
}
public DatasetArtifactSymbol(DatasetArtifactKind kind, String artifact, String jar, String id) {
super(kind, artifact, jar, id);
}
public String getJar() {
return getValue(1);
}
public String getId() {
return getValue(2);
}
@Override
public String toString() {
return super.toString();
}
public static class DatasetArtifactKind extends TagKind {
public static final DatasetArtifactKind INSTANCE = new DatasetArtifactKind();
protected DatasetArtifactKind() {}
}
}
package de.monticore.lang.monticar.emadl.tagging.artifacttag;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAComponentSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.embeddedmontiarcdynamic._symboltable.instanceStructure.EMADynamicComponentInstantiationSymbol;
import de.monticore.lang.tagging._ast.ASTNameScope;
import de.monticore.lang.tagging._ast.ASTTag;
import de.monticore.lang.tagging._ast.ASTTagBody;
import de.monticore.lang.tagging._ast.ASTTaggingUnit;
import de.monticore.lang.tagging._symboltable.TagSymbolCreator;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.SymbolKind;
import de.monticore.types.types._ast.ASTQualifiedName;
import de.se_rwth.commons.Joiners;
import de.se_rwth.commons.logging.Log;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DatasetArtifactSymbolCreator implements TagSymbolCreator {
protected final String regexExpression = "\\s*\\{\\s*artifact\\s*=\\s*(.+):(.+):(.+)\\s*\\}\\s*";
protected final Pattern pattern = Pattern.compile(regexExpression, Pattern.MULTILINE);
@Override
public void create(ASTTaggingUnit taggingUnit, TaggingResolver resolver) {
boolean hasLayerArtifactParameterTag =
taggingUnit.getQualifiedNameList().stream()
.map(ASTQualifiedName::toString)
.anyMatch(n -> n.endsWith("DatasetArtifactTagSchema"));
if (!hasLayerArtifactParameterTag) {
return;
}
final String packageName = Joiners.DOT.join(taggingUnit.getPackageList());
final ASTTagBody tagBody = taggingUnit.getTagBody();
final String root =
(tagBody.getTargetModelOpt().isPresent()) ?
Joiners.DOT.join(packageName, tagBody.getTargetModelOpt().get()
.getQualifiedNameString()) :
packageName;
for (ASTTag tag : taggingUnit.getTagBody().getTagList()) {
addTag(tag, resolver, root, EMADynamicComponentInstantiationSymbol.KIND);
addTag(tag, resolver, root, EMAComponentSymbol.KIND);
}
}
protected void addTag(ASTTag tag, TaggingResolver tagging, String root, SymbolKind kind) {
tag.getTagElementList().stream()
.filter(tagElement -> tagElement.getName().equals("DatasetArtifact"))
.forEachOrdered(tagElement -> {
Matcher matcher = matchRegexPattern(tagElement.getTagValue());
tag.getScopeList().stream()
.filter(scope -> scope.getScopeKind().equals("NameScope"))
.map(scope -> (ASTNameScope) scope)
.map(scope ->
tagging.resolve(dotJoin(root, scope.getQualifiedNameString()), kind)
)
.filter(Optional::isPresent)
.map(Optional::get)
.forEachOrdered(scope -> {
String artifact = String.format("%s%s%s%s%s", matcher.group(1).replace('.', File.separatorChar),
File.separator, matcher.group(2), File.separator, matcher.group(3));
String jar = String.format("%s-%s-dataset", matcher.group(2), matcher.group(3));
tagging.addTag(scope, new LayerArtifactParameterSymbol(artifact, jar, matcher.group(4))); }
);
});
}
protected Matcher matchRegexPattern(String regex) {
Matcher matcher = pattern.matcher(regex);
if (matcher.matches()) {
return matcher;
}
else {
Log.error(
String.format(
"'%s' does not match the specified regex pattern '%s'",
regex, "{artifact = {groupId:artifactId:version}}"
)
);
return null;
}
}
protected String dotJoin(String root, String name) {
if (StringUtils.isEmpty(root)) {
return name;
}
else {
return Joiners.DOT.join(root, name);
}
}
}
package de.monticore.lang.monticar.emadl.tagging.artifacttag;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.resolving.CommonResolvingFilter;
public class DatasetArtifactTagSchema {
protected static DatasetArtifactTagSchema instance = null;
protected DatasetArtifactTagSchema() {}
protected static DatasetArtifactTagSchema getInstance() {
if (instance == null) {
instance = new DatasetArtifactTagSchema();
}
return instance;
}
protected void doRegisterTagTypes(TaggingResolver resolver) {
resolver.addTagSymbolCreator(new DatasetArtifactSymbolCreator());
resolver.addTagSymbolResolvingFilter(CommonResolvingFilter.create(DatasetArtifactSymbol.KIND));
}
protected void registerTagTypes(TaggingResolver resolver) {
getInstance().doRegisterTagTypes(resolver);
}
}
......@@ -5,7 +5,7 @@
* can be found under https://github.com/MontiCore/monticore.
*/
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.emadl.tagging.dltag;
package de.monticore.lang.monticar.emadl.tagging.artifacttag;
import de.monticore.lang.tagging._symboltable.TagKind;
import de.monticore.lang.tagging._symboltable.TagSymbol;
......
......@@ -5,7 +5,7 @@
* can be found under https://github.com/MontiCore/monticore.
*/
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.emadl.tagging.dltag;
package de.monticore.lang.monticar.emadl.tagging.artifacttag;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAComponentSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.embeddedmontiarcdynamic._symboltable.instanceStructure.EMADynamicComponentInstantiationSymbol;
......@@ -73,7 +73,6 @@ public class LayerArtifactParameterSymbolCreator implements TagSymbolCreator {
.forEachOrdered(scope -> {
String artifact = String.format("%s%s%s%s%s", matcher.group(1).replace('.', File.separatorChar),
File.separator, matcher.group(2), File.separator, matcher.group(3));
// TODO: change dataset to pretrained
String jar = String.format("%s-%s-pretrained", matcher.group(2), matcher.group(3));
tagging.addTag(scope, new LayerArtifactParameterSymbol(artifact, jar, matcher.group(4))); }
);
......
......@@ -5,7 +5,7 @@
* can be found under https://github.com/MontiCore/monticore.
*/
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.emadl.tagging.dltag;
package de.monticore.lang.monticar.emadl.tagging.artifacttag;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.resolving.CommonResolvingFilter;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment