-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(argparse): Shifted from argparse to plac
- Loading branch information
1 parent
406955b
commit 28e37a3
Showing
23 changed files
with
211 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,4 @@ include atarashi/data/Ngram_keywords.json | |
|
||
prune .git | ||
prune venv | ||
prune test* | ||
|
||
prune test* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
__author__ = "Aman Jain" | ||
__email__ = "[email protected]" | ||
|
||
import argparse | ||
import plac | ||
from enum import Enum | ||
import itertools | ||
import time | ||
|
@@ -151,28 +151,22 @@ def setSimAlgo(self, newAlgo): | |
self.algo = newAlgo | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-s", "--tfidf_similarity", required=False, | ||
default="ScoreSim", | ||
choices=["CosineSim", "ScoreSim"], | ||
help="Specify the similarity algorithm that you want") | ||
parser.add_argument("inputFile", help="Specify the input file which needs to be scanned") | ||
parser.add_argument("processedLicenseList", | ||
help="Specify the processed license list file which contains licenses") | ||
parser.add_argument("-v", "--verbose", help="increase output verbosity", | ||
action="count", default=0) | ||
args = parser.parse_args() | ||
|
||
tfidf_similarity = args.tfidf_similarity | ||
filename = args.inputFile | ||
licenseList = args.processedLicenseList | ||
verbose = args.verbose | ||
@plac.annotations( | ||
filename = plac.Annotation("Specify the input file which needs to be scanned", metavar="inputFile"), | ||
licenseList = plac.Annotation("Specify the processed license list file which contains licenses", "positional", None, str, metavar="processedLicenseList"), | ||
tfidf_similarity = plac.Annotation("Specify the similarity algorithm that you want", "option", "s", str, ["CosineSim", "ScoreSim"], metavar="{CosineSim,ScoreSim}"), | ||
verbose = plac.Annotation("increase output verbosity", "flag", "v") | ||
) | ||
|
||
|
||
def main(filename, licenseList, tfidf_similarity="ScoreSim", verbose=False): | ||
scanner = TFIDF(licenseList, verbose=verbose) | ||
if tfidf_similarity == "CosineSim": | ||
scanner.setSimAlgo(TFIDF.TfidfAlgo.cosineSim) | ||
print("License Detected using TF-IDF algorithm + cosine similarity " + str(scanner.scan(filename))) | ||
else: | ||
scanner.setSimAlgo(TFIDF.TfidfAlgo.scoreSim) | ||
print("License Detected using TF-IDF algorithm + sum score " + str(scanner.scan(filename))) | ||
|
||
if __name__ == "__main__": | ||
plac.call(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
__author__ = "Aman Jain" | ||
__email__ = "[email protected]" | ||
|
||
import argparse | ||
import plac | ||
import re | ||
|
||
from atarashi.agents.atarashiAgent import AtarashiAgent, exactMatcher | ||
|
@@ -79,19 +79,18 @@ def scan(self, filePath): | |
return temp | ||
|
||
|
||
if __name__ == "__main__": | ||
print("The file has been called from main") | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("inputFile", help = "Specify the input file which needs to be scanned") | ||
parser.add_argument("processedLicenseList", | ||
help = "Specify the processed license list file which contains licenses") | ||
parser.add_argument("-v", "--verbose", help = "increase output verbosity", | ||
action = "count", default = 0) | ||
|
||
args = parser.parse_args() | ||
filename = args.inputFile | ||
licenseList = args.processedLicenseList | ||
verbose = args.verbose | ||
@plac.annotations( | ||
filename = plac.Annotation("Specify the input file which needs to be scanned", metavar="inputFile"), | ||
licenseList = plac.Annotation("Specify the processed license list file which contains licenses", "positional", None, str, metavar="processedLicenseList"), | ||
verbose = plac.Annotation("increase output verbosity", "flag", "v") | ||
) | ||
|
||
|
||
def main(filename, licenseList, verbose=False): | ||
print("The file has been called from main") | ||
scanner = WordFrequencySimilarity(licenseList, verbose = verbose) | ||
print("The result from Histogram similarity algo is ", scanner.scan(filename)) | ||
|
||
|
||
if __name__ == "__main__": | ||
plac.call(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
__author__ = "Gaurav Mishra" | ||
__email__ = "[email protected]" | ||
|
||
import argparse | ||
import plac | ||
import os | ||
import sys | ||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/../') | ||
|
@@ -40,7 +40,12 @@ | |
The merged CSV is then processesed which is then used to create the Ngrams. | ||
""" | ||
|
||
def download_dependencies(threads = os.cpu_count(), verbose = 0): | ||
@plac.annotations( | ||
threads = plac.Annotation("No of threads to use for download. Default: CPU count", "option", "t", int, metavar="THREADS"), | ||
verbose = plac.Annotation("increase output verbosity", "flag", "v") | ||
) | ||
|
||
def download_dependencies(threads = os.cpu_count(), verbose = False): | ||
currentDir = os.path.dirname(os.path.abspath(__file__)) | ||
licenseListCsv = currentDir + "/data/licenses/licenseList.csv" | ||
processedLicenseListCsv = currentDir + "/data/licenses/processedLicenses.csv" | ||
|
@@ -59,14 +64,4 @@ def download_dependencies(threads = os.cpu_count(), verbose = 0): | |
createNgrams(processedLicenseListCsv, ngramJsonLoc, threads, verbose) | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-t", "--threads", required = False, default = os.cpu_count(), | ||
type = int, | ||
help = "No of threads to use for download. Default: CPU count") | ||
parser.add_argument("-v", "--verbose", help = "increase output verbosity", | ||
action = "count", default = 0) | ||
args = parser.parse_args() | ||
threads = args.threads | ||
verbose = args.verbose | ||
|
||
download_dependencies(threads, verbose) | ||
plac.call(download_dependencies) |
Oops, something went wrong.