Skip to content

Instantly share code, notes, and snippets.

@Kuo-TingKai
Last active July 27, 2022 15:27
Show Gist options
  • Save Kuo-TingKai/36c8cb3faa400a38ca4f3c18a1ee1352 to your computer and use it in GitHub Desktop.
Save Kuo-TingKai/36c8cb3faa400a38ca4f3c18a1ee1352 to your computer and use it in GitHub Desktop.
Error Correction Code Zoo knowledge graph spider
import requests
from bs4 import BeautifulSoup
def get_linear_parent_chain(entry_code = 'string net',entry_url = 'string_net'):
URL = "https://errorcorrectionzoo.org/c/"
url=URL+entry_url
depth = 0
hasParent = True
linear_parent_tree = {-1:entry_code}
while(hasParent):
#print("depth:",depth)
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
try:
parents = soup.find("ul", class_="code-relations-list code-parents-list").find_all("a")
# Now: only implemnt chain of parents, not tree
#print("1")
for i,p in enumerate(parents):
if 'code' in p.text:
# print(p.text)
# print(p['href'].split("/")[-1])
# print("\n")
None
if i==0:
url = URL+(p['href'].split("/")[-1])
linear_parent_tree[depth]=p.text
depth+=1
except:
hasParent = False
#print(linear_parent_tree)
cnt = 1
for k,v in linear_parent_tree.items():
if cnt<len(linear_parent_tree):
print(v)
print("^\n|")
cnt+=1
else:
print(v)
get_linear_parent_chain()
@Kuo-TingKai
Copy link
Author

I wrote a web spider to backtrack the parent class of quantum error correction code (ECC) iteratively until there is no parent.
Now I only implement the ancestor chain of the ECC.
In the future, I will implement the ancestor tree of the ECC.

linear_parent_chain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment