Skip to content
Snippets Groups Projects
Unverified Commit 706ce7a2 authored by darrylong's avatar darrylong Committed by GitHub
Browse files

Add multimodality table to documentation (#639)

parent 5c8cd20b
No related branches found
No related tags found
No related merge requests found
import json
import os
import glob
def get_key_val(part):
key_index_start = part.index('[')
......@@ -13,48 +14,8 @@ def get_key_val(part):
return key, val
# Read the content from README.md
with open('../README.md', 'r') as file:
content = file.read()
# Extract the relevant information from the content
models = []
lines = content.split('\n')
lines = lines[lines.index('## Models') + 4: lines.index('## Resources') - 2]
headers = []
headers = lines[0].split('|')[1:-1]
headers = [header.strip() for header in headers]
for line in lines[2:]:
parts = line.split('|')[1:-1]
parts = [part.strip() for part in parts]
model = dict(zip(headers, parts))
models.append(model)
year = None
for model in models:
# handle empty years
if model["Year"] == "":
model["Year"] = year
else:
year = model["Year"]
# handle model, docs and paper part
name_paper_str = model["Model and Paper"]
for i, part in enumerate(name_paper_str.split(', ')):
key, val = get_key_val(part)
if i == 0:
model["Name"] = key
model["Link"] = val
else:
model[key] = val
def add_pytorch_tensorflow(model):
# handle environment part
env_part = model["Environment"].split(', ')[0]
search_dict = {
......@@ -74,28 +35,117 @@ for model in models:
else:
for header, _ in search_dict.items():
model[header] = False
def add_modalities_for_model(model):
modalities_keywords = {
"User Text": "user_text",
"User Image": "user_image",
"User Graph": "user_graph",
"Item Text": "item_text",
"Item Image": "item_image",
"Item Graph": "item_graph",
"Sentiment": "sentiment",
"Review Text": "review_text",
}
# remove non required keys
model.pop("Model and Paper")
model.pop("Environment")
# Get package name
model_dir = model["Link"]
for filename in glob.glob(f'../{model["Link"]}/*.py', recursive=True):
with open(filename, 'r') as file:
file_data = file.read()
for header, modality_keyword in modalities_keywords.items():
is_found = modality_keyword in file_data
if is_found:
model[header] = True
# for user feature and item feature
# >> if user feature is found, we set user text, image and graph to true
is_found = "user_feature" in file_data
if is_found:
model["User Text"] = True
model["User Image"] = True
model["User Graph"] = True
# likewise for item feature
is_found = "item_feature" in file_data
if is_found:
model["Item Text"] = True
model["Item Image"] = True
model["Item Graph"] = True
with open(f'../{model_dir}/__init__.py', 'r') as file:
init_data = file.read()
for header, modality_keyword in modalities_keywords.items():
if header not in model:
model[header] = False
if __name__ == "__main__":
# Read the content from README.md
with open('../README.md', 'r') as file:
content = file.read()
# Extract the relevant information from the content
models = []
lines = content.split('\n')
lines = lines[lines.index('## Models') + 4: lines.index('## Resources') - 2]
headers = []
headers = lines[0].split('|')[1:-1]
headers = [header.strip() for header in headers]
for line in lines[2:]:
parts = line.split('|')[1:-1]
parts = [part.strip() for part in parts]
model = dict(zip(headers, parts))
models.append(model)
year = None
for model in models:
# handle empty years
if model["Year"] == "":
model["Year"] = year
else:
year = model["Year"]
# handle model, docs and paper part
name_paper_str = model["Model and Paper"]
for i, part in enumerate(name_paper_str.split(', ')):
key, val = get_key_val(part)
if i == 0:
model["Name"] = key
model["Link"] = val
else:
model[key] = val
package_names = []
# Check for PyTorch and TensorFlow in each requirements file
add_pytorch_tensorflow(model)
for row in init_data.split('\n'):
if "import" in row:
package_name = row[row.index("import") + len("import "):]
package_names.append(f"cornac.models.{package_name}")
# Check for modalities keywords in files and add to model
add_modalities_for_model(model)
# remove non required keys
model.pop("Model and Paper")
model.pop("Environment")
model["packages"] = package_names
# Get package name
model_dir = model["Link"]
with open(f'../{model_dir}/__init__.py', 'r') as file:
init_data = file.read()
package_names = []
for row in init_data.split('\n'):
if "import" in row:
package_name = row[row.index("import") + len("import "):]
package_names.append(f"cornac.models.{package_name}")
model["packages"] = package_names
json_str = json.dumps(models, indent=4)
json_str = json.dumps(models, indent=4)
# Write the JSON object to a file
with open('source/_static/models/data.js', 'w') as file:
file.write(f"var data = {json_str};")
# Write the JSON object to a file
with open('source/_static/models/data.js', 'w') as file:
file.write(f"var data = {json_str};")
This diff is collapsed.
......@@ -127,12 +127,12 @@
{
field: "PyTorch",
headerName: "PyTorch",
cellRenderer: params => params.value ? "" : "",
cellRenderer: params => params.value ? "" : "",
},
{
field: "TensorFlow",
headerName: "TensorFlow",
cellRenderer: params => params.value ? "" : "",
cellRenderer: params => params.value ? "" : "",
},
],
defaultColDef: {
......
<html lang="en">
<head>
<script src="https://cdn.jsdelivr.net/npm/ag-grid-community/dist/ag-grid-community.min.js"></script>
</head>
<body>
<h3>Models with Modalities</h3>
<br />
<div id="modalityGrid" class="ag-theme-quartz-auto-dark" style="height: 500px"></div>
</body>
</html>
<script type="text/javascript" src="data.js"></script>
<script type="text/javascript" src="../_static/models/data.js"></script>
<script type="text/javascript" src="_static/models/data.js"></script>
<script type="text/javascript">
function LinkRenderer(url, title) {
return `<a href="${url}" target="_blank">${title}</a>`
}
// Grid API: Access to Grid API methods
let modalityGridApi;
// Grid Options: Contains all of the grid configurations
const modalityGridOptions = {
// Data to be displayed
rowData: data,
// Columns to be displayed (Should match rowData properties)
columnDefs: [
{ field: "Year" },
{
field: "Name",
headerName: "Model Name (Hover over for package name)",
flex: 4,
cellRenderer: params => LinkRenderer(params.data.docs, params.data.Name),
tooltipValueGetter: (params) => "Package Name: " + params.data.packages,
},
{
headerName: "Text",
children: [
{
field: "User Text",
headerName: "User",
cellRenderer: params => params.value ? "" : "",
},
{
field: "Item Text",
headerName: "Item",
cellRenderer: params => params.value ? "" : "",
},
]
},
{
headerName: "Image",
children: [
{
field: "User Image",
headerName: "User",
cellRenderer: params => params.value ? "" : "",
},
{
field: "Item Image",
headerName: "Item",
cellRenderer: params => params.value ? "" : "",
},
]
},
{
headerName: "Graph",
children: [
{
field: "User Graph",
headerName: "User",
cellRenderer: params => params.value ? "" : "",
},
{
field: "Item Graph",
headerName: "Item",
cellRenderer: params => params.value ? "" : "",
},
]
},
{
field: "Sentiment",
headerName: "Sentiment",
cellRenderer: params => params.value ? "" : "",
},
{
field: "Review Text",
headerName: "Review Text",
cellRenderer: params => params.value ? "" : "",
},
],
defaultColDef: {
flex: 1,
filter: true,
// floatingFilter: true,
},
pagination: true,
paginationAutoPageSize: true
};
// Create Grid: Create new grid within the #myGrid div, using the Grid Options object
modalityGridApi = agGrid.createGrid(document.querySelector("#modalityGrid"), modalityGridOptions);
</script>
<style>
/* Make h2 bigger */
.bd-page-width {
width: 100%;
}
.bd-main .bd-content .bd-article-container {
max-width: 100%; /* default is 60em */
}
.ag-theme-quartz-auto-dark {
/* add border between cell columns */
--ag-cell-horizontal-border: solid rgb(230, 230, 230);
}
</style>
......@@ -100,6 +100,16 @@ html_theme_options = {
},
"pygment_light_style": "default",
"pygment_dark_style": "github-dark",
"secondary_sidebar_items": {
"**": ["page-toc", "sourcelink"],
"index": [],
"models/index": [],
}
}
html_sidebars = {
"models/index": [],
"index": [],
}
# -- Options for intersphinx extension ---------------------------------------
......
......@@ -114,4 +114,12 @@ Quick Links
:expand:
:click-parent:
Contributor's Guide
\ No newline at end of file
Contributor's Guide
.. raw:: html
<style>
.bd-main .bd-content .bd-article-container {
max-width: 100%;
}
</style>
......@@ -5,4 +5,7 @@ Below shows a list of models available in Cornac.
Clicking on the model name will take you to the model's API documentation.
.. raw:: html
:file: ../_static/models/models.html
\ No newline at end of file
:file: ../_static/models/models.html
.. raw:: html
:file: ../_static/models/models_modalities.html
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment