Skip to content

Commit

Permalink
renamed utils.entity_utils.py to utils.java_utils.py + moved data fil…
Browse files Browse the repository at this point in the history
…es related to hist, decor, incode and jdeodorant to their respective directories in approaches/
  • Loading branch information
antoineBarbez committed Oct 11, 2019
1 parent cab0e0b commit b872289
Show file tree
Hide file tree
Showing 83 changed files with 55 additions and 244 deletions.
Binary file modified approaches/.DS_Store
Binary file not shown.
Binary file modified approaches/decor/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion approaches/decor/core_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os

def getGCCoreMetrics(systemName):
decorMetricsFile = os.path.join(ROOT_DIR, 'data', 'metric_files', 'decor', systemName + '.csv')
decorMetricsFile = os.path.join(ROOT_DIR, 'approaches', 'decor', 'metric_files', systemName + '.csv')

dictionnary = {c:[0., 0., 0, 0] for c in data_utils.getClasses(systemName)}
with open(decorMetricsFile, 'rb') as csvfile:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified approaches/hist/.DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions approaches/hist/core_metrics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from context import ROOT_DIR

import utils.data_utils as data_utils
import utils.entity_utils as entity_utils
import utils.java_utils as java_utils
import numpy as np

import csv
Expand Down Expand Up @@ -54,7 +54,7 @@ def getFECoreMetrics(systemName):

for i, m in enumerate(methods):
# Get the number of co-occurrences with methods of its own class (i.e., the embedding class)
idx_embedding_class = classToIndexMap[entity_utils.getEmbeddingClass(m)]
idx_embedding_class = classToIndexMap[java_utils.getEmbeddingClass(m)]
nb_co_occ_ec = 0.5 if co_occ_matrix[i, idx_embedding_class] == 0 else co_occ_matrix[i, idx_embedding_class]

co_occ_matrix[i,:] = co_occ_matrix[i,:]/nb_co_occ_ec
Expand Down Expand Up @@ -84,7 +84,7 @@ def getHistory(systemName, granularity):
'''

dirName = {"C": "class_changes", "M": "method_changes"}
historyFile = os.path.join(ROOT_DIR, 'data', 'history', dirName[granularity], systemName + '.csv')
historyFile = os.path.join(ROOT_DIR, 'approaches', 'hist', 'history', dirName[granularity], systemName + '.csv')
with open(historyFile, 'rb') as csvfile:
reader = csv.DictReader(csvfile, delimiter=';')
rawHistory = [{key: row[key] for key in row} for row in reader]
Expand Down Expand Up @@ -143,7 +143,7 @@ def getCoOccurrenceMatrix(systemName):
# Get the classes where these "other methods" are implemented
klasses = []
for m in coMethods:
embeddingClass = entity_utils.getEmbeddingClass(m)
embeddingClass = java_utils.getEmbeddingClass(m)
if embeddingClass in classes:
klasses.append(embeddingClass)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified approaches/incode/.DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions approaches/incode/core_metrics.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from context import ROOT_DIR

import utils.data_utils as data_utils
import utils.entity_utils as entity_utils
import utils.java_utils as java_utils

import csv
import os


def getFECoreMetrics(systemName):
incodeMetricsFile = os.path.join(ROOT_DIR, 'data', 'metric_files', 'incode', systemName + '.csv')
incodeMetricsFile = os.path.join(ROOT_DIR, 'approaches', 'incode', 'metric_files', systemName + '.csv')

dictionnary = {e:[0., 0., 0.] for e in data_utils.getEntities('feature_envy', systemName)}

Expand All @@ -29,7 +29,7 @@ def getFECoreMetrics(systemName):

if (currentMethodName != methodName):
classToMetricMap = getClassToMetricMap(currentClassName, classAttributeMap)
normMethodName = entity_utils.normalizeMethodName(currentMethodName)
normMethodName = java_utils.normalizeMethodName(currentMethodName)
for klass in classToMetricMap:
entityName = normMethodName + ';' + klass
if entityName in dictionnary:
Expand All @@ -48,7 +48,7 @@ def getFECoreMetrics(systemName):
classAttributeMap[row['DeclaringClass']] = int(row['NbFields'])

classToMetricMap = getClassToMetricMap(currentClassName, classAttributeMap)
normMethodName = entity_utils.normalizeMethodName(currentMethodName)
normMethodName = java_utils.normalizeMethodName(currentMethodName)
for klass in classToMetricMap:
entityName = normMethodName + ';' + klass
if entityName in dictionnary:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified approaches/jdeodorant/.DS_Store
Binary file not shown.
16 changes: 8 additions & 8 deletions approaches/jdeodorant/core_metrics.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from context import ROOT_DIR

import utils.data_utils as data_utils
import utils.entity_utils as entity_utils
import utils.java_utils as java_utils

import csv
import os

def getGCCoreMetrics(systemName):
JDMetricsFile = os.path.join(ROOT_DIR, 'data', 'metric_files', 'jdeodorant', 'god_class_output', systemName + '.txt')
JDMetricsFile = os.path.join(ROOT_DIR, 'approaches', 'jdeodorant', 'metric_files', 'god_class_output', systemName + '.txt')

dictionnary = {c: [0] for c in data_utils.getClasses(systemName)}
with open(JDMetricsFile, 'r') as file:
Expand All @@ -21,7 +21,7 @@ def getGCCoreMetrics(systemName):


def getFECoreMetrics(systemName):
JDMetricsFile = os.path.join(ROOT_DIR, 'data', 'metric_files', 'jdeodorant', 'feature_envy_metrics', systemName + '.csv')
JDMetricsFile = os.path.join(ROOT_DIR, 'approaches', 'jdeodorant', 'metric_files', 'feature_envy_metrics', systemName + '.csv')

dictionnary = {e:[0., 0., 0.] for e in data_utils.getEntities('feature_envy', systemName)}
with open(JDMetricsFile, 'rb') as metricfile:
Expand All @@ -34,7 +34,7 @@ def getFECoreMetrics(systemName):
method = data[0]['Method']
for i, line in enumerate(data):
if method != line['Method']:
normMethodName = entity_utils.normalizeMethodName(method)
normMethodName = java_utils.normalizeMethodName(method)
for tc in targetClasses:
entityName = normMethodName + ';' + tc['name']

Expand All @@ -53,14 +53,14 @@ def getFECoreMetrics(systemName):
distanceToEnclosingClass = 1.0
method = line['Method']

if entity_utils.getEmbeddingClass(entity_utils.normalizeMethodName(method)) == line['TargetClass']:
if java_utils.getEmbeddingClass(java_utils.normalizeMethodName(method)) == line['TargetClass']:
nbAccessToEnclosingClass = float(line['NbAccessedEntities'])
distanceToEnclosingClass = float(line['Distance_TC'])
else:
targetClasses.append({'name':line['TargetClass'], 'nbAccess':float(line['NbAccessedEntities']), 'distance':float(line['Distance_TC'])})

if i == len(data)-1:
normMethodName = entity_utils.normalizeMethodName(method)
normMethodName = java_utils.normalizeMethodName(method)
for tc in targetClasses:
entityName = normMethodName + ';' + tc['name']

Expand All @@ -74,14 +74,14 @@ def getFECoreMetrics(systemName):
if entityName in dictionnary:
dictionnary[entityName] = [nbAccessMetric, distanceMetric, 0.0]

JDOutputFile = os.path.join(ROOT_DIR, 'data', 'metric_files', 'jdeodorant', 'feature_envy_output', systemName + '.txt')
JDOutputFile = os.path.join(ROOT_DIR, 'approaches', 'jdeodorant', 'metric_files', 'feature_envy_output', systemName + '.txt')
with open(JDOutputFile, 'r') as file:
i = 0
for line in file:
if i > 0:
method = line.split('\t')[1].replace('::', '.')
method = method.split(':')[0]
method = entity_utils.normalizeMethodName(method)
method = java_utils.normalizeMethodName(method)
targetClass = line.split('\t')[2]
entityName = method + ';' + targetClass;

Expand Down
4 changes: 2 additions & 2 deletions approaches/jdeodorant/detection_feature_envy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import utils.data_utils as data_utils
import utils.detection_utils as detection_utils
import utils.entity_utils as entity_utils
import utils.java_utils as java_utils

import os

Expand All @@ -18,7 +18,7 @@ def detect(systemName):
if i > 0:
source_entity = line.split('\t')[1].replace('::', '.')
source_entity = source_entity.split(':')[0]
source_entity = entity_utils.normalizeMethodName(source_entity)
source_entity = java_utils.normalizeMethodName(source_entity)
target_class = line.split('\t')[2]

if source_entity in methods:
Expand Down
File renamed without changes.
Binary file modified data/.DS_Store
Binary file not shown.
Binary file removed data/metric_files/.DS_Store
Binary file not shown.
10 changes: 5 additions & 5 deletions data_construction/oracle_feature_envy/createOracle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from context import ROOT_DIR

import utils.entity_utils as entity_utils
import utils.java_utils as java_utils
import numpy as np

import csv
Expand Down Expand Up @@ -62,7 +62,7 @@ def getScore(answers):
return np.mean(np.array(floatValues))

def getAnswers():
answerDir = os.path.join(ROOT_DIR, 'data_construction/oracle_feature_envy/forms_answers')
answerDir = os.path.join(ROOT_DIR, 'data_construction', 'oracle_feature_envy','forms_answers')

answers = []
for path, dirs, files in os.walk(answerDir):
Expand All @@ -74,14 +74,14 @@ def getAnswers():
return answers

def getCandidates():
candidateDir = os.path.join(ROOT_DIR, 'data_construction/oracle_feature_envy/candidate_set/')
candidateDir = os.path.join(ROOT_DIR, 'data_construction', 'oracle_feature_envy' 'candidate_set')

candidates = []
for path, dirs, files in os.walk(candidateDir):
for file in fnmatch.filter(sorted(files), '*.csv'):
with open(os.path.join(path, file), 'r') as csvFile:
reader = csv.DictReader(csvFile)
candidates += [row['EMBED_CLASS'] + '.' + entity_utils.normalizeMethodName(row['METHOD']) + ';' + row['ENVIED_CLASS'] for row in reader]
candidates += [row['EMBED_CLASS'] + '.' + java_utils.normalizeMethodName(row['METHOD']) + ';' + row['ENVIED_CLASS'] for row in reader]

return candidates

Expand All @@ -95,7 +95,7 @@ def getCandidates():
smells = [candidates[i] for i in range(startIndex, endIndex) if getScore(answers[i]) >= 0.5]
startIndex = endIndex

labelFile = os.path.join(ROOT_DIR, 'data/antipatterns/feature_envy/' + system['name'] + '.txt')
labelFile = os.path.join(ROOT_DIR, 'data', 'antipatterns', 'feature_envy', system['name'] + '.txt')

with open(labelFile, 'w') as file:
for smell in smells:
Expand Down
26 changes: 14 additions & 12 deletions data_construction/repository_miner/history_extractor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from context import ROOT_DIR

import utils.entity_utils as entity_utils
import utils.java_utils as java_utils

import javalang
import os
Expand Down Expand Up @@ -61,21 +61,21 @@ def createHistoryFile(self, historyFilePath, granularity):


def __getClassChange(self, SHA, date, filePath, changeType):
directory = entity_utils.getDirectory(filePath)
directory = java_utils.getDirectory(filePath)
if directory in self.package_dirs_dictionary:
package = self.package_dirs_dictionary[directory]
else:
try:
if os.path.isfile(filePath):
package = entity_utils.getPackage(filePath)
package = java_utils.getPackage(filePath)
else:
if changeType == 'D':
self.__updateWorkingFile("../previousFile.java", filePath, SHA + "^")
package = entity_utils.getPackage("../previousFile.java")
package = java_utils.getPackage("../previousFile.java")

else:
self.__updateWorkingFile("../actualFile.java", filePath, SHA)
package = entity_utils.getPackage("../actualFile.java")
package = java_utils.getPackage("../actualFile.java")
except (javalang.tokenizer.LexerError, javalang.parser.JavaSyntaxError, AttributeError):
package = directory
self.exceptionDirs.append(directory)
Expand All @@ -85,12 +85,12 @@ def __getClassChange(self, SHA, date, filePath, changeType):
self.package_dirs_dictionary[directory] = package


line = SHA + ';' + date + ';' + package + '.' + entity_utils.getClassName(filePath) + ';' + changeType + '\n'
line = SHA + ';' + date + ';' + package + '.' + java_utils.getClassName(filePath) + ';' + changeType + '\n'
return line


def __getMethodeChange(self, SHA, date, filePath, changeType):
directory = entity_utils.getDirectory(filePath)
directory = java_utils.getDirectory(filePath)
if directory in self.package_dirs_dictionary:
package = self.package_dirs_dictionary[directory]
else:
Expand All @@ -101,7 +101,9 @@ def __getMethodeChange(self, SHA, date, filePath, changeType):
self.__updateWorkingFile("../actualFile.java", filePath, SHA)
self.__updateWorkingFile("../previousFile.java", filePath, SHA + "^")

diffjCommand = "java -jar " + ROOT_DIR + "/assets/jar/diffj-1.6.3.jar --brief ../previousFile.java ../actualFile.java"
diffj_jar = os.path.join(ROOT_DIR, 'assets', 'jar', 'diffj-1.6.3.jar')

diffjCommand = "java -jar " + diffj_jar + " --brief ../previousFile.java ../actualFile.java"
ps = subprocess.Popen(diffjCommand.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = ps.communicate()

Expand All @@ -113,9 +115,9 @@ def __getMethodeChange(self, SHA, date, filePath, changeType):

if (ct == "ADDED") | (ct == "BODY_MODIFIED"):
if actual_method_class_dictionary is None:
actual_method_class_dictionary = entity_utils.getMethodClassDictionary("../actualFile.java")
actual_method_class_dictionary = java_utils.getMethodClassDictionary("../actualFile.java")

method = entity_utils.normalizeMethodName(method)
method = java_utils.normalizeMethodName(method)
if (method in actual_method_class_dictionary):
method = actual_method_class_dictionary[method] + '.' + method

Expand All @@ -125,9 +127,9 @@ def __getMethodeChange(self, SHA, date, filePath, changeType):

if ct == "DELETED":
if previous_method_class_dictionary is None:
previous_method_class_dictionary = entity_utils.getMethodClassDictionary("../previousFile.java")
previous_method_class_dictionary = java_utils.getMethodClassDictionary("../previousFile.java")

method = entity_utils.normalizeMethodName(method)
method = java_utils.normalizeMethodName(method)
if (method in previous_method_class_dictionary):
method = previous_method_class_dictionary[method] + '.' + method

Expand Down
Loading

0 comments on commit b872289

Please sign in to comment.