Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void main(String[] args) {

private void printEvaluationResult(EvaluationResult evaluationResult) {
System.out.println("==================");
System.out.println("EVALUATION RESULT FOR " + evaluationResult.getAlgorithm().getDescriptionString());
System.out.println("EVALUATION RESULT FOR " + evaluationResult.getAlgorithm().getName());
System.out.println("Number of good: " + evaluationResult.getNumberOfGood());
System.out.println("Number of found good: " + evaluationResult.getNumberOfFoundGood());
System.out.println("Number of bad: " + evaluationResult.getNumberOfBad());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void writeTable(List<EvaluationResult> evaluationResults, Path outPath) t
lines.add("<tr>");
lines.addAll(Arrays.asList("<th>", "", "</th>"));
for (EvaluationResult evaluationResult : evaluationResults) {
lines.addAll(Arrays.asList("<th>", evaluationResult.getAlgorithm().getDescriptionString(), "</th>"));
lines.addAll(Arrays.asList("<th>", evaluationResult.getAlgorithm().getName(), "</th>"));
}
lines.add("</tr>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.sixrr.stockmetrics.classMetrics.NumMethodsClassMetric;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.research.groups.ml_methods.algorithm.AlgorithmsRepository.AlgorithmType;
import org.jetbrains.research.groups.ml_methods.algorithm.attributes.*;
import org.jetbrains.research.groups.ml_methods.algorithm.distance.DistanceCalculator;
import org.jetbrains.research.groups.ml_methods.algorithm.distance.RelevanceBasedDistanceCalculator;
Expand All @@ -28,7 +27,7 @@ public class ARI extends AbstractAlgorithm {
private static final @NotNull DistanceCalculator distanceCalculator = RelevanceBasedDistanceCalculator.getInstance();

public ARI() {
super(AlgorithmType.ARI, true);
super("ARI", true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а ты в этом уверен?

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.research.groups.ml_methods.algorithm.AlgorithmsRepository.AlgorithmType;
import org.jetbrains.research.groups.ml_methods.algorithm.attributes.AttributesStorage;
import org.jetbrains.research.groups.ml_methods.logging.Logging;
import org.jetbrains.research.groups.ml_methods.refactoring.CalculatedRefactoring;
Expand Down Expand Up @@ -36,30 +35,21 @@
public abstract class AbstractAlgorithm implements Algorithm {
private static final Logger LOGGER = Logging.getLogger(AbstractAlgorithm.class);

private final AlgorithmType algorithmType;
private final String name;

private final boolean enableParallelExecution;

/**
* {@inheritDoc}
*/
@NotNull
@Override
public AlgorithmType getAlgorithmType() {
return algorithmType;
}

public AbstractAlgorithm(AlgorithmType algorithmType, boolean enableParallelExecution) {
this.algorithmType = algorithmType;
public AbstractAlgorithm(final @NotNull String name, final boolean enableParallelExecution) {
this.name = name;
this.enableParallelExecution = enableParallelExecution;
}

/**
* {@inheritDoc}
*/
@Override
public @NotNull String getDescriptionString() {
return algorithmType.toString();
public @NotNull String getName() {
return name;
}

/**
Expand All @@ -71,7 +61,7 @@ public AbstractAlgorithm(AlgorithmType algorithmType, boolean enableParallelExec
final @Nullable ExecutorService service,
final boolean enableFieldRefactorings
) {
LOGGER.info(algorithmType + " started");
LOGGER.info(name + " started");
final long startTime = System.currentTimeMillis();
final ProgressIndicator indicator;

Expand All @@ -82,7 +72,7 @@ public AbstractAlgorithm(AlgorithmType algorithmType, boolean enableParallelExec
}

indicator.pushState();
indicator.setText("Running " + algorithmType + "...");
indicator.setText("Running " + name + "...");
indicator.setFraction(0);

final ExecutionContext context = new ExecutionContext(
Expand All @@ -97,16 +87,16 @@ public AbstractAlgorithm(AlgorithmType algorithmType, boolean enableParallelExec
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception e) {
LOGGER.error(algorithmType + " finished with error: " + e);
return new AlgorithmResult(algorithmType, e);
LOGGER.error(name + " finished with error: " + e);
return new AlgorithmResult(this, e);
}

final long time = System.currentTimeMillis() - startTime;
indicator.popState();

final AlgorithmResult result = new AlgorithmResult(refactorings, algorithmType, time, context.usedThreads);
final AlgorithmResult result = new AlgorithmResult(refactorings, this, time, context.usedThreads);

LOGGER.info(algorithmType + " successfully finished");
LOGGER.info(name + " successfully finished");
LOGGER.info(result.getReport());

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.List;
import java.util.concurrent.ExecutorService;

import static org.jetbrains.research.groups.ml_methods.algorithm.AlgorithmsRepository.AlgorithmType;

/**
* An algorithm that analyses given {@link AttributesStorage} and produces refactoring suggestions
* as an {@link AlgorithmResult}.
Expand All @@ -36,12 +34,7 @@ public interface Algorithm {
/**
* Returns a short textual description of this algorithm.
*/
@NotNull String getDescriptionString();

/**
* Returns a type of algorithm. Should be used to identify algorithm and request it by enum type not by name.
*/
@NotNull AlgorithmType getAlgorithmType();
@NotNull String getName();

/**
* Returns an array of metrics from which a features vectors for this particular algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,34 @@

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.research.groups.ml_methods.algorithm.AlgorithmsRepository.AlgorithmType;
import org.jetbrains.research.groups.ml_methods.refactoring.CalculatedRefactoring;

import java.util.Collections;
import java.util.List;

public class AlgorithmResult {
private final List<CalculatedRefactoring> refactorings;
private final AlgorithmType algorithmType;
private final Algorithm algorithm;
private final long executionTime;
private final int threadUsed;
private final Exception exception;

AlgorithmResult(@NotNull List<CalculatedRefactoring> refactorings, AlgorithmType algorithmType, long executionTime,
int threadUsed) {
AlgorithmResult(
final @NotNull List<CalculatedRefactoring> refactorings,
final @NotNull Algorithm algorithm,
final long executionTime,
final int threadUsed
) {
this.refactorings = refactorings;
this.algorithmType = algorithmType;
this.algorithm = algorithm;
this.executionTime = executionTime;
this.threadUsed = threadUsed;
this.exception = null;
}

AlgorithmResult(AlgorithmType algorithmType, @NotNull Exception exception) {
AlgorithmResult(final @NotNull Algorithm algorithm, final @NotNull Exception exception) {
this.refactorings = Collections.emptyList();
this.algorithmType = algorithmType;
this.algorithm = algorithm;
this.executionTime = 0;
this.threadUsed = 0;
this.exception = exception;
Expand All @@ -36,8 +39,8 @@ public List<CalculatedRefactoring> getRefactorings() {
return Collections.unmodifiableList(refactorings);
}

public AlgorithmType getAlgorithmType() {
return algorithmType;
public Algorithm getAlgorithm() {
return algorithm;
}

public long getExecutionTime() {
Expand All @@ -58,7 +61,7 @@ public boolean isSuccess() {
}

public String getReport() {
return "Results of " + algorithmType + " running" + System.lineSeparator() +
return "Results of " + algorithm.getName() + " running" + System.lineSeparator() +
" Found " + refactorings.size() + " refactorings" + System.lineSeparator() +
" Execution time: " + executionTime + System.lineSeparator() +
" Threads used: " + threadUsed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@

public class AlgorithmsRepository {
private static final List<Algorithm> ALGORITHMS = Arrays.asList(
new ARI(),
new CCDA(),
new HAC()
new ARI(),
new CCDA(),
new HAC()
);

public static Optional<Algorithm> getAlgorithmByName(String algorithmName) {
return ALGORITHMS.stream().filter(algorithm -> algorithm.getDescriptionString().equals(algorithmName)).findAny();
}

public enum AlgorithmType {
ARI, CCDA, HAC
return ALGORITHMS.stream().filter(algorithm -> algorithm.getName().equals(algorithmName)).findAny();
}

@Contract(pure = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.sixrr.stockmetrics.classMetrics.NumMethodsClassMetric;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.research.groups.ml_methods.algorithm.AlgorithmsRepository.AlgorithmType;
import org.jetbrains.research.groups.ml_methods.algorithm.attributes.AttributesStorage;
import org.jetbrains.research.groups.ml_methods.algorithm.attributes.ClassAttributes;
import org.jetbrains.research.groups.ml_methods.algorithm.attributes.ClassInnerEntityAttributes;
Expand All @@ -26,7 +25,7 @@ public class CCDA extends AbstractAlgorithm {
private static final double ACCURACY = 1;

public CCDA() {
super(AlgorithmType.CCDA, true);
super("CCDA", true);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.research.groups.ml_methods.algorithm.AlgorithmsRepository.AlgorithmType;
import org.jetbrains.research.groups.ml_methods.algorithm.attributes.*;
import org.jetbrains.research.groups.ml_methods.algorithm.distance.DistanceCalculator;
import org.jetbrains.research.groups.ml_methods.algorithm.distance.RelevanceBasedDistanceCalculator;
Expand All @@ -31,7 +30,7 @@ public class HAC extends AbstractAlgorithm {
private static final @NotNull DistanceCalculator distanceCalculator = RelevanceBasedDistanceCalculator.getInstance();

public HAC() {
super(AlgorithmType.HAC, true);
super("HAC", true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.concurrent.Executors;
import java.util.function.Consumer;

import static org.jetbrains.research.groups.ml_methods.algorithm.AlgorithmsRepository.AlgorithmType;
import static org.jetbrains.research.groups.ml_methods.algorithm.AlgorithmsRepository.getAvailableAlgorithms;

/**
Expand Down Expand Up @@ -139,8 +138,8 @@ private void calculate(Algorithm algorithm) {
);
} catch (NoRequestedMetricException e) {
LOGGER.error(
"Error during attributes creation for '" + algorithm.getDescriptionString() +
"' algorithm: " + e.getMessage() + " - " + algorithm.getDescriptionString() +
"Error during attributes creation for '" + algorithm.getName() +
"' algorithm: " + e.getMessage() + " - " + algorithm.getName() +
"is aborted"
);

Expand All @@ -157,9 +156,9 @@ public List<AlgorithmResult> getAlgorithmResults() {
return new ArrayList<>(algorithmsResults);
}

public AlgorithmResult getResultForType(AlgorithmType algorithmType) {
public AlgorithmResult getResultForAlgorithm(Algorithm algorithm) {
return algorithmsResults.stream()
.filter(result -> algorithmType.equals(result.getAlgorithmType()))
.filter(result -> algorithm.equals(result.getAlgorithm()))
.findAny().orElse(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@SuppressWarnings("WeakerAccess")
public abstract class AlgorithmAbstractTest extends ScopeAbstractTest {
protected final TestCasesCheckers testCasesChecker =
new TestCasesCheckers(getAlgorithm().getAlgorithmType());
new TestCasesCheckers(getAlgorithm());

protected RefactoringExecutionContext createContext(
AnalysisScope scope,
Expand Down
Loading