This file contains hidden or 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
| from SPARQLWrapper import SPARQLWrapper, JSON | |
| sparql = SPARQLWrapper("http://localhost:8890/sparql") | |
| for i in range(25): | |
| query = """ | |
| select ?slabel ?olabel | |
| where { | |
| ?s rdfs:subClassOf ?o. | |
| ?s rdf:type owl:Class. | |
| ?o rdf:type owl:Class. |
This file contains hidden or 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
| ## verex list | |
| SELECT p.page_id, p.page_title | |
| FROM page p | |
| WHERE p.page_namespace=0 | |
| INTO OUTFILE '/tmp/vertices.tsv' | |
| FIELDS TERMINATED BY ' '; | |
| ## edge list | |
| SELECT l.pl_from, p.page_id | |
| FROM page p, pagelinks l |
This file contains hidden or 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
| import pandas as pd | |
| csv = pd.read_csv(file_name) | |
| # csv | |
| # "0", "1" | |
| # Tom, 2 | |
| # John, 3 | |
| #... | |
| csv["2"] = np.zeros(len(csv)) | |
| for i in range(len(csv)): |
This file contains hidden or 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
| import os | |
| import shutil | |
| import random | |
| src_name = 'train/' | |
| drc_name = 'val/' | |
| src_dir = os.listdir(src_name)[1:] | |
| for sub_src_dir in src_dir: | |
| os.mkdir(drc_name+sub_src_dir) |
This file contains hidden or 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
| import tweepy | |
| import time | |
| api = tweepy.API(auth) | |
| with open("log.txt", 'w') as f: | |
| for i in range(1,100): | |
| users_tweets = api.user_timeline(id=user,page=i,include_entities=True,count=100) | |
| for tweet in users_tweets: | |
| f.write(tweet.entities['urls'][0]["expanded_url"] + "\n") | |
| time.sleep(30) |
This file contains hidden or 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
| from html.parser import HTMLParser | |
| import urllib.request | |
| import re | |
| def download(url, path): | |
| with urllib.request.urlopen(url) as file: | |
| file_name = path + "/" + url.split("/")[-1] | |
| with open(file_name, 'wb') as local: | |
| local.write(file.read()) |
This file contains hidden or 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
| import timeit | |
| import functools | |
| @functools.lru_cache(maxsize=None) | |
| def fib(x): | |
| if x < 2: | |
| return x | |
| return fib(x-1) + fib(x-2) | |
| print(timeit.timeit('fib(100)', setup="from __main__ import fib")) |
This file contains hidden or 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
| import matplotlib | |
| import os | |
| # style setting | |
| matplotlib.style.use('seaborn-white') | |
| # font setting | |
| fp = matplotlib.font_manager.FontProperties(fname=os.path.expanduser('~/Library/Fonts/ipaexg.ttf')) | |
| plt.rcParams['font.family'] = fp.get_name() | |
| plt.plot(0, 1) |
This file contains hidden or 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
| \begin{tikzpicture}[->,>=stealth,shorten >=1pt,auto,node distance=2cm, | |
| semithick, | |
| val/.style={circle,fill=cyan,opacity=.6}] | |
| \node[val] (a) {$1$}; | |
| \node[right=0.1cm of a] (a1) {$u_{1}$}; | |
| \node[above=0.1cm of a] (b) {$l$}; | |
| \node[below=0.3cm of a] (c) {$\vdots$}; | |
| \node[val, below=0.3cm of c] (d) {$i$}; | |
| \node[below=0.3cm of d] (d2) {$\vdots$}; | |
| \node[right=0.1cm of d] (d1) {$u_{i}$}; |
This file contains hidden or 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
| from functools import singledispatch | |
| import numpy as np | |
| @singledispatch | |
| def test_function(arg): | |
| print("default") | |
| @test_function.register(int) | |
| def _(arg): | |
| print(f"arg is integer {arg}") |
OlderNewer