Skip to content

Commit

Permalink
conversion scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
taiya committed Dec 17, 2023
1 parent 1117e74 commit 5b116cb
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 11 deletions.
42 changes: 31 additions & 11 deletions convert_to_bibtex.py → python/bib_json_to_bibtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
author={AUTHORS},
booktitle={{CONFERENCE}},
year={YEAR},
note={NOTES},
note={\\textbf{NOTES}},
}"""

_journal_template="""
Expand All @@ -16,7 +16,7 @@
author={AUTHORS},
journal={{CONFERENCE}},
year={YEAR},
note={NOTES},
note={\\textbf{NOTES}},
}"""

_techreport_template="""
Expand All @@ -25,17 +25,24 @@
author={AUTHORS},
institution={{INSTITUTION}},
year={YEAR},
note={NOTES},
note={\\textbf{NOTES}},
}"""

_arxiv_template="""
@misc{KEY,
title={{TITLE}},
title={\\normalfont{``TITLE''}},
author={AUTHORS},
institution={{INSTITUTION}},
year={YEAR},
url={URL},
note={(arXiv preprint)},
}"""

_patent_template="""
@patent{KEY,
title={TITLE},
author={AUTHORS},
number={NUMBER},
year={YEAR},
note={NOTES},
}"""

_workshop_template="""
Expand All @@ -44,7 +51,7 @@
author={AUTHORS},
institution={{INSTITUTION}},
year={YEAR},
note={NOTES},
note={\\textbf{NOTES}},
}"""

_course_template="""
Expand All @@ -53,7 +60,7 @@
author={AUTHORS},
howpublished={{HOWPUBLISHED}},
year={YEAR},
note={NOTES},
note={\\textbf{NOTES}},
}"""

def list_to_string(mylist):
Expand Down Expand Up @@ -103,10 +110,20 @@ def arxiv(pub):
if 'arxiv' in pub:
ret = ret.replace("URL", pub['arxiv'])
else:
ret = ret.replace("URL", "https://arxiv.org")
ret = ret.replace("URL", "")
ret = ret.replace("NOTES", notes_to_string(pub['notes']) if "notes" in pub else "")
return ret

def patent(pub):
ret = _patent_template
ret = ret.replace("KEY", pub['key'])
ret = ret.replace("TITLE", pub['title'])
ret = ret.replace("AUTHORS", list_to_string(pub['authors']))
ret = ret.replace("YEAR", pub['year'])
ret = ret.replace("NUMBER", pub['number'])
ret = ret.replace("NOTES", f"Filed: {pub['filed']}")
return ret

def course(pub):
ret = _course_template
ret = ret.replace("KEY", pub['key'])
Expand All @@ -123,10 +140,13 @@ def dispatcher(pub):
if pub['type'] == 'techreport': return techreport(pub)
if pub['type'] == 'course': return course(pub)
if pub['type'] == 'arxiv': return arxiv(pub)
if pub['type'] == 'patent': return patent(pub)
raise ValueError(pub['type'])

with open('pubs.json', 'r') as fp:
with open('../pubs.json', 'r') as fp:
data = json.load(fp)
for pub in data:
# if pub['key'] != "chen2020bspnet": continue #TODO
print(dispatcher(pub))
text = dispatcher(pub)
text = text.replace("Andrea Tagliasacchi", "\\textcolor{BrickRed}{Andrea Tagliasacchi}")
print(text)
51 changes: 51 additions & 0 deletions python/patents_ccvxml_to_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import xml.etree.ElementTree as ET
import json

# Read XML content from a file
file_path = 'ccv_patents.xml'

# Parse the XML content
tree = ET.parse(file_path)
root = tree.getroot()

# Create a list to hold the converted data
data = []

# Iterate through each 'section' in the XML
for section in root.findall('section'):
section_data = {}

# Get values from the fields within each section
for field in section.findall('field'):
label = field.get('label')
value = field.find('value')
lov = field.find('lov')
if value is not None and value.text:
section_data[label.lower().replace(' ', '_')] = value.text.strip()
elif lov is not None and lov.text:
section_data[label.lower().replace(' ', '_')] = lov.text.strip()

# Extract inventors list and get the first inventor
inventors_list = section_data.get("inventors", "").split(';')
first_inventor = inventors_list[0].strip() if inventors_list else ""

# Create the desired JSON structure
formatted_data = {
"type": "patent",
"key": f"{first_inventor.lower().replace(' ', '')}{section_data.get('filing_date', '').split('-')[0]}patent",
"title": section_data.get("patent_title", ""),
"status": section_data.get("patent_status", "").lower(),
"filed": section_data.get("filing_date", ""),
"authors": [author.strip() for author in inventors_list],
"patent_number": section_data.get("patent_number", "")
}

# Append formatted data to the list
data.append(formatted_data)

# Convert the list of dictionaries to JSON
json_data = json.dumps(data, indent=2)

# Write JSON data to a file
with open('converted_data.json', 'w') as json_file:
json_file.write(json_data)
48 changes: 48 additions & 0 deletions python/talks_ccvxml_to_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import xml.etree.ElementTree as ET
import json

# Read XML content from a file
file_path = 'ccv_talks.xml'

# Parse the XML content
tree = ET.parse(file_path)
root = tree.getroot()

# Create a list to hold the converted data
data = []

# Iterate through each 'section' in the XML
for section in root.findall('section'):
section_data = {}

# Get values from the fields within each section
for field in section.findall('field'):
label = field.get('label')
value = field.find('value')
lov = field.find('lov')
if value is not None and value.text:
section_data[label.lower()] = value.text
elif lov is not None and lov.text == 'Yes':
section_data[label.lower()] = 'Yes'

# if "keynote?" in section_data:
# print(section_data.get("keynote?", "").lower())

# Create the desired JSON structure
formatted_data = {
"title": section_data.get("presentation title", ""),
"event": section_data.get("conference / event name", ""),
"location": f"{section_data.get('city', '')} ({section_data.get('location', '')})",
"year": section_data.get("presentation year", ""),
"keynote": section_data.get("keynote?", "").lower() if "keynote?" in section_data else "no"
}

# Append formatted data to the list
data.append(formatted_data)

# Convert the list of dictionaries to JSON
json_data = json.dumps(data, indent=2)

# Write JSON data to a file
with open('ccv_talks.json', 'w') as json_file:
json_file.write(json_data)
17 changes: 17 additions & 0 deletions python/talks_json_to_latex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import json

# Read JSON content from a file
file_path = 'ccv_talks.json'

# Read JSON data from file
with open(file_path, 'r') as json_file:
data = json.load(json_file)

# Iterate through each entry in the JSON data
for entry in data:
template = """\\item \\ressubheading{event}{location}{title}{year}"""
template = template.replace("event", entry['event'])
template = template.replace("location", entry['location'])
template = template.replace("title", entry['title'])
template = template.replace("year", entry['year'])
print(template)

0 comments on commit 5b116cb

Please sign in to comment.