Skip to content

Commit

Permalink
Mod/Fix: Update SPICE installation check and fix zip file remove.
Browse files Browse the repository at this point in the history
  • Loading branch information
Labbeti committed Sep 25, 2023
1 parent 877aa6b commit 83f8c22
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/aac_metrics/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def _download_spice(
clean_archives: bool = True,
verbose: int = 0,
) -> None:
"""
"""Download SPICE java code.
Target SPICE directory tree:
Expand Down Expand Up @@ -228,8 +228,6 @@ def _download_spice(
│ └── stanford-corenlp-3.6.0-models.jar
└── spice-1.0.jar
"""
# TODO: rm use_shell arg ?

# Download JAR files for SPICE metric
spice_cache_dpath = osp.join(cache_path, DNAME_SPICE_CACHE)
spice_jar_dpath = osp.join(cache_path, osp.dirname(FNAME_SPICE_JAR))
Expand Down Expand Up @@ -316,8 +314,8 @@ def _download_spice(
spice_zip_fname = DATA_URLS["spice_zip"]["fname"]
spice_zip_fpath = osp.join(spice_cache_dpath, spice_zip_fname)

shutil.rmtree(spice_zip_fpath)
shutil.rmtree(spice_unzip_dpath)
os.remove(spice_zip_fpath)
os.remove(spice_unzip_dpath)


def _download_fense(
Expand Down
45 changes: 41 additions & 4 deletions src/aac_metrics/functional/spice.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ def spice(
use_shell = platform.system() == "Windows"

if __debug__:
if not osp.isfile(spice_fpath):
raise FileNotFoundError(
f"Cannot find JAR file '{spice_fpath}' for SPICE metric. Maybe run 'aac-metrics-download' or specify another 'cache_path' directory."
)
check_spice_install(cache_path)

if not check_java_path(java_path):
raise RuntimeError(
f"Invalid Java executable to compute SPICE score. ({java_path})"
Expand Down Expand Up @@ -221,6 +219,45 @@ def spice(
return spice_score


def check_spice_install(cache_path: str) -> None:
spice_fpath = osp.join(cache_path, FNAME_SPICE_JAR)
if not osp.isfile(spice_fpath):
raise FileNotFoundError(
f"Cannot find JAR file '{spice_fpath}' for SPICE metric. Maybe run 'aac-metrics-download' or specify another 'cache_path' directory."
)

expected_jar_in_lib = [
"ejml-0.23.jar",
"fst-2.47.jar",
"guava-19.0.jar",
"hamcrest-core-1.3.jar",
"jackson-core-2.5.3.jar",
"javassist-3.19.0-GA.jar",
"json-simple-1.1.1.jar",
"junit-4.12.jar",
"lmdbjni-0.4.6.jar",
"lmdbjni-linux64-0.4.6.jar",
"lmdbjni-osx64-0.4.6.jar",
"lmdbjni-win64-0.4.6.jar",
"Meteor-1.5.jar",
"objenesis-2.4.jar",
"SceneGraphParser-1.0.jar",
"slf4j-api-1.7.12.jar",
"slf4j-simple-1.7.21.jar",
"stanford-corenlp-3.6.0.jar",
"stanford-corenlp-3.6.0-models.jar",
]
names = os.listdir(osp.join(cache_path, DNAME_SPICE_CACHE, "lib"))
files_not_found = []
for fname in expected_jar_in_lib:
if fname not in names:
files_not_found.append(fname)
if len(files_not_found) > 0:
raise FileNotFoundError(
f"Missing {len(files_not_found)} files in SPICE lib directory. (missing {', '.join(files_not_found)})"
)


def __run_spice(
i: int,
timeout_i: Optional[int],
Expand Down

0 comments on commit 83f8c22

Please sign in to comment.