def solve(self): ''' insert your code ''' with open('./neko.txt.mecab', 'r') as f: morphologies = [] sentence = [] for line in f.readlines(): if line == 'EOS\n': if len(sentence) > 0: morphologies.append(sentence) sentence = [] else: surface, result = line.split() results = result.split(',') sentence.append({ 'surface': surface, 'base': results[6], 'pos': results[0], 'pos1': results[1] }) pc = PickleCache() pc.set('./neko.txt.mecab.pickle', morphologies) return None
def solve(self): ''' insert your code ''' pc = PickleCache() morphologies = pc.get('./neko.txt.mecab.pickle') for sentence in morphologies: for m in sentence: if m['pos'] == '動詞': print m['surface'] return None
def solve(self): ''' insert your code ''' pc = PickleCache() morphologies = pc.get('./neko.txt.mecab.pickle') for sentence in morphologies: for i in range(len(sentence)): if sentence[i]['surface'] == 'の' and 0 < i < len(sentence) - 1 and sentence[i-1]['pos'] == '名詞' and sentence[i+1]['pos'] == '名詞': print sentence[i-1]['surface'] + sentence[i]['surface'] + sentence[i+1]['surface'] return None
def solve(self): ''' insert your code ''' pc = PickleCache() morphologies = pc.get('./neko.txt.mecab.pickle') for sentence in morphologies: for m in sentence: if m['pos'] == '名詞' and m['pos1'] == 'サ変接続': print m['surface'] return None
def solve(self): ''' insert your code ''' pc = PickleCache() morphologies = pc.get('./neko.txt.mecab.pickle') words = [m['base'] for sentence in morphologies for m in sentence] count = Counter(words) for word, freq in count.most_common(): print word, freq return None
def solve(self): ''' insert your code ''' pc = PickleCache() morphologies = pc.get('./neko.txt.mecab.pickle') words = [m['base'] for sentence in morphologies for m in sentence] count = Counter(words) plt.hist([f for w, f in count.items()], bins=100, range=(0, 10000)) plt.title('Histogram of Term Frequency in Bocchan') plt.xlabel('Term Frequency') plt.ylabel('Freqency') plt.show() return None
def solve(self): ''' insert your code ''' pc = PickleCache() morphologies = pc.get('./neko.txt.mecab.pickle') for sentence in morphologies: noun_phrase = [] for m in sentence: if m['pos'] == '名詞': noun_phrase.append(m['surface']) else: if len(noun_phrase) >= 2: print ''.join(noun_phrase) noun_phrase = [] return None
def solve(self): ''' insert your code ''' pc = PickleCache() morphologies = pc.get('./neko.txt.mecab.pickle') for sentence in morphologies: noun_phrase = [] for m in sentence: if m['pos'] == '名詞': noun_phrase.append(m['surface']) else: if len(noun_phrase) >= 2: print ''.join(noun_phrase) noun_phrase = [] return None
def solve(self): ''' insert your code ''' pc = PickleCache() morphologies = pc.get('./neko.txt.mecab.pickle') words = [m['base'] for sentence in morphologies for m in sentence] count = Counter(words) top10 = count.most_common(10) ind = np.arange(10) width = 0.35 plt.bar(ind, [f for w, f in top10], width) plt.title('Top 10 of Term Frequency in Bocchan') plt.xlabel('Terms') plt.ylabel('Frequency') plt.xticks(ind + width / 2, [w.decode('utf-8') for w, f in top10]) plt.show() return None
def solve(self): ''' insert your code ''' pc = PickleCache() morphologies = pc.get('./neko.txt.mecab.pickle') words = [m['base'] for sentence in morphologies for m in sentence] count = Counter(words) top = count.most_common() rank = np.arange(len(top)) + 1 freq = [f for w, f in top] plt.scatter(rank, freq, s=10) plt.title('Relationship between Rank and Value of Term Frequency') plt.xlabel('Rank (Logarithmic)') plt.ylabel('Term Frequency (Logarithmic)') plt.xscale('log') plt.yscale('log') plt.show() return None
def solve(self): ''' insert your code ''' pc = PickleCache() morphologies = pc.get('./neko.txt.mecab.pickle') words = [m['base'] for sentence in morphologies for m in sentence] count = Counter(words) top = count.most_common() rank = np.arange(len(top)) + 1 freq = [f for w, f in top] plt.scatter(rank, freq, s=10) plt.title('Relationship between Rank and Value of Term Frequency') plt.xlabel('Rank (Logarithmic)') plt.ylabel('Term Frequency (Logarithmic)') plt.xscale('log') plt.yscale('log') plt.show() return None
def solve(self): ''' insert your code ''' with open('./neko.txt.mecab', 'r') as f: morphologies = [] sentence = [] for line in f.readlines(): if line == 'EOS\n': if len(sentence) > 0: morphologies.append(sentence) sentence = [] else: surface, result = line.split() results = result.split(',') sentence.append({'surface': surface, 'base': results[6], 'pos': results[0], 'pos1': results[1]}) pc = PickleCache() pc.set('./neko.txt.mecab.pickle', morphologies) return None
import string from random import randint, sample from dataclasses import dataclass from typing import Any from random import choice from graphviz import Digraph import seaborn as sns from pickle_cache import PickleCache import kanren as kr import os import libcst as cst import json from pymongo import MongoClient sns.set() pcache = PickleCache() all_names = list(set(string.ascii_lowercase) - set(["l", "i"])) all_operators = ["+", "-"] def shuffle(l): return sample(l, k=len(l)) def shuffle_unique(l): while True: l2 = shuffle(l) if l2 != l: return l2
self._run = run if run: log.debug('-- START: {} --'.format(s)) def __enter__(self): self.start = now() def __exit__(self, a, b, c): t = int(now() - self.start) if self._run: log.debug('-- END: {} -- {:02d}:{:02d}:{:02d}'.format( self._s, int(t / 3600), int((t / 60) % 60), int(t) % 60)) pcache = PickleCache(cache_dir='/app/.cache') def crop(img, bbox): [h, w] = img.shape[:2] return img[int(bbox.bbox_y1 * h):int(bbox.bbox_y2 * h), int(bbox.bbox_x1 * w):int(bbox.bbox_x2 * w)] def resize(img, w, h): th = int(img.shape[0] * (w / float(img.shape[1]))) if h is None else int(h) tw = int(img.shape[1] * (h / float(img.shape[0]))) if w is None else int(w) return cv2.resize(img, (tw, th)) def load_frame(video, frame, bboxes):
import javalang from javalang import tree import textwrap import os from pickle_cache import PickleCache from dataclasses import dataclass, replace from iterextras import par_for import copy from enum import Enum from typing import Dict, Union, Optional, List, Any from unionfind import UnionFind from torch.distributions import Categorical from torch import tensor as t pcache = PickleCache('.pcache') DATA_DIR = '../../data/cs106a/CheckerboardKarel/CheckerboardKarel_anonymized' GRADES_DIR = '../../data/cs106a/CheckerboardKarel/CheckerboardKarel_results' STUDENTS = os.listdir(DATA_DIR) @dataclass class Program: source: str ast: tree.CompilationUnit def load_student_programs(student): files = sorted(os.listdir(f'{DATA_DIR}/{student}')) programs = [] for f in files:
def pc(): # with tempfile.TemporaryDirectory() as dirname: dirname = tempfile.TemporaryDirectory().__enter__() print(dirname) pc = PickleCache(cache_dir=dirname) yield pc