repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
Unimer | Unimer-master/executions/atis/lambda_calculus/lc_evaluator.py | # coding=utf8
import logging
from pprint import pprint
from multiprocessing import Process, Manager
from .query import *
from .transform import transform_lambda_calculus
class TimeoutException(Exception):
pass
def get_result(lambda_calculus, return_dict):
python_lf, _, _, _= transform_lambda_calculus(
... | 4,093 | 32.834711 | 145 | py |
Unimer | Unimer-master/executions/atis/lambda_calculus/transform.py | # coding=utf8
import re
import copy
from pprint import pprint
from .query import process_entity_string
ENTITY_PATTERN = re.compile(r'^[A-Z|a-z|\\]+:_([a-z]+)$')
ENTITY_TYPE_SET = set()
FUNCTION_NAME_SET = set()
FUNCTION_REPLACE_MAP = {
"_abbrev": [{"name": "abbrev", "number_of_argument": 1, "argument_type": ["... | 61,471 | 51.006768 | 169 | py |
Unimer | Unimer-master/executions/atis/lambda_calculus/query.py | # coding=utf8
import sys
sys.path += ['..']
import re
import mysql.connector
from pprint import pprint
db = None
def normalize(sql):
s = re.sub(' +', ' ', sql)
s = s.replace('MAX (', 'MAX(')
s = s.replace('MIN (', 'MIN(')
s = s.replace('AVG (', 'AVG(')
s = s.replace('COUNT (', 'COUNT(')
s = ... | 82,088 | 35.811211 | 416 | py |
Unimer | Unimer-master/executions/jobs/evaluate_sql.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/executions/jobs/evaluate_lambda_calculus.py | # coding=utf8
| 16 | 3.25 | 13 | py |
Unimer | Unimer-master/executions/jobs/evaluate_funql.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/executions/jobs/evaluate_prolog.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/executions/jobs/funql/transform.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/executions/jobs/funql/evaluator.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/executions/jobs/funql/__init__.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/executions/jobs/funql/query.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/executions/jobs/sql/parse_job_data.py | # coding=utf8
import re
import mysql.connector
from pprint import pprint
db = mysql.connector.connect(
host="localhost",
user="root",
passwd="123456",
database="job",
auth_plugin='mysql_native_password'
)
def parse_entry(value):
first_index = value.index('(')
last_index = value.rindex('... | 2,748 | 25.432692 | 91 | py |
Unimer | Unimer-master/executions/jobs/sql/evaluator.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/executions/jobs/sql/__init__.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/executions/jobs/lambda/transform.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/executions/jobs/lambda/__init__.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/metrics/sequency_accuracy.py | # coding=utf8
import torch
from overrides import overrides
from allennlp.training.metrics import Metric
from typing import Union, Tuple, Dict, List, Optional
class SequenceAccuracy(Metric):
def __init__(self) -> None:
self._correct_counts = 0.
self._total_counts = 0.
self._pad_index = -1... | 1,684 | 29.636364 | 118 | py |
Unimer | Unimer-master/metrics/__init__.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/data_readers/gnn_data_reader.py | # coding=utf8
import re
import copy
import numpy as np
from typing import Iterable, Callable, List, Dict
from overrides import overrides
from allennlp.data import Instance, Tokenizer
from allennlp.data.fields import TextField, ArrayField, MetadataField
from allennlp.common.util import START_SYMBOL, END_SYMBOL
from all... | 9,933 | 44.360731 | 120 | py |
Unimer | Unimer-master/data_readers/seq2seq_data_reader.py | # coding=utf-8
import numpy as np
from typing import Iterable, Callable
from overrides import overrides
from allennlp.data import Instance
from allennlp.data.fields import TextField, ArrayField, MetadataField
from allennlp.common.util import START_SYMBOL, END_SYMBOL
from allennlp.data.dataset_readers import DatasetRe... | 4,976 | 42.278261 | 131 | py |
Unimer | Unimer-master/data_readers/grammar_based_reader.py | # coding=utf-8
import re
import os
import json
import copy
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from typing import Iterator, List, Dict, Iterable, Tuple, Callable
from overrides import overrides
from allennlp.data import Instance
from allennlp.data.fields import TextField, ArrayField,... | 4,192 | 43.606383 | 154 | py |
Unimer | Unimer-master/data_readers/__init__.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/data_readers/grammar_copy_based_reader.py | # coding=utf-8
import numpy as np
from typing import Iterable, Callable
from overrides import overrides
from allennlp.data import Instance
from allennlp.data.fields import TextField, ArrayField, MetadataField
from allennlp.common.util import START_SYMBOL, END_SYMBOL
from allennlp.data.dataset_readers import DatasetRea... | 5,214 | 45.981982 | 126 | py |
Unimer | Unimer-master/data/atis/log_to_csv.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/data/atis/lambda_calculus_to_prolog.py | # coding=utf8
import re
import copy
ENTITY_PATTERN = re.compile(r'^[A-Z|a-z|\\|_|\d]+:_([a-z]+)$')
ENTITY_TYPE_MAP = {
"ac": "aircraft_code",
"al": "airline_code",
"ci": "city_name",
"ap": "airport_code",
"fn": "flight_number",
"cl": "class_description",
"ti": "time",
"pd": "day_pe... | 57,781 | 45.560838 | 148 | py |
Unimer | Unimer-master/data/atis/lambda_calculus_to_funql.py | # coding=utf8
import re
import copy
from pprint import pprint
from lambda_calculus_to_prolog import FUNCTION_REPLACE_MAP
ENTITY_PATTERN = re.compile(r'^[A-Z|a-z|\\|_|\d]+:_([a-z]+)$')
ENTITY_TYPE_MAP = {
"ac": "aircraft_code",
"al": "airline_code",
"ci": "city_name",
"ap": "airport_code",
"fn":... | 32,555 | 41.062016 | 113 | py |
Unimer | Unimer-master/data/job/log_to_csv.py | # coding=utf8
if __name__ == '__main__':
questions, logical_forms = list(), list()
with open("job_funql_train.log", 'r') as f:
lines = f.readlines()
lidx = 0
while lidx < len(lines):
line = lines[lidx]
line = line.strip()
print(lidx)
if le... | 1,040 | 32.580645 | 68 | py |
Unimer | Unimer-master/data/job/funql_to_lambda.py | # coding-utf8
import re
def read_data(path):
questions, logical_forms = list(), list()
with open(path, 'r') as f:
for line in f:
line = line.strip()
splits = line.split('\t')
questions.append(splits[0])
logical_forms.append(splits[1])
return questi... | 7,857 | 37.145631 | 104 | py |
Unimer | Unimer-master/data/job/funql_to_sql.py | # coding=utf8
import re
import mysql.connector
db = mysql.connector.connect(
host="localhost",
user="root",
passwd="123456",
database="job",
auth_plugin='mysql_native_password'
)
def get_result(sql):
_sql = sql
cursor = db.cursor()
cursor.execute(_sql)
# print(cursor.description... | 19,937 | 37.268714 | 107 | py |
Unimer | Unimer-master/data/job/auto_funql_transform.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/data/job/prolog_to_funql.py | # coding=utf8
import re
def tokenize_prolog(logical_form):
# Tokenize Prolog
normalized_lf = logical_form.replace(" ", "::")
replacements = [
('(', ' ( '),
(')', ' ) '),
(',', ' , '),
(';', ' ; '),
("\\+", " \\+ "),
]
for a, b in replacements:
norm... | 11,528 | 34.042553 | 106 | py |
Unimer | Unimer-master/grammars/entity_matcher.py | # coding=utf8
import os
import re
import numpy as np
from typing import List
from overrides import overrides
from nltk.corpus import stopwords
from allennlp.data.tokenizers import Token
from .atis.atis_entity_matcher import ATISEntityMatcher
from .atis.atis_sql_entity_matcher import ATISSQLEntityMatcher
from .atis.ati... | 5,894 | 40.223776 | 116 | py |
Unimer | Unimer-master/grammars/utils.py | # coding=utf8
import re
from collections import defaultdict
from sys import exc_info
from typing import List, Dict, Set
from overrides import overrides
from parsimonious.exceptions import VisitationError, UndefinedLabel
from parsimonious.expressions import Literal, OneOf, Sequence
from parsimonious.grammar import Gra... | 21,295 | 40.8389 | 128 | py |
Unimer | Unimer-master/grammars/parse_ast.py | # coding=utf8
from grammars.basic import ProductionRule
from grammars.utils import action_sequence_to_logical_form
class ASTNode:
def __init__(self, production_rule: ProductionRule, parent, node_id: int, nonterminals_to_skip: list = None):
self._production_rule = production_rule
if nonterminals_t... | 6,741 | 27.935622 | 115 | py |
Unimer | Unimer-master/grammars/grammar.py | # coding=utf8
import copy
from typing import List, Dict, Set
from pprint import pprint
from parsimonious.exceptions import ParseError
from parsimonious.grammar import Grammar as _Grammar
from grammars.basic import ProductionRule
from grammars.utils import format_grammar_string, initialize_valid_actions, SqlVisitor
fro... | 11,090 | 50.586047 | 138 | py |
Unimer | Unimer-master/grammars/__init__.py | # coding=utf-8 | 14 | 14 | 14 | py |
Unimer | Unimer-master/grammars/basic.py | # coding=utf8
from typing import List, Dict
class ProductionRule:
def __init__(self, rule_id: int, rule: str, lhs: str, rhs: List[str], rhs_nonterminal: List[str], attrs: Dict = None):
self._rule = rule
self._rule_id = rule_id
self._lhs = lhs
self._rhs = rhs
self._rhs_nonte... | 1,139 | 21.8 | 122 | py |
Unimer | Unimer-master/grammars/gnn_entity_matcher.py | # coding=utf8
import os
from .geo import geo_entity_extractor, geo_gnn_entity_matcher
from .atis import atis_entity_extractor, atis_gnn_entity_matcher
def get_gnn_entity_matcher(task, language):
matcher = None
if task == 'geo':
base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'... | 3,164 | 38.5625 | 102 | py |
Unimer | Unimer-master/grammars/geo/get_funql_terminals.py | # coding=utf8
import re
stateid_pattern = re.compile('stateid\((.*?)\)')
riverid_pattern = re.compile('riverid\((.*?)\)')
countryid_pattern = re.compile('countryid\((.*?)\)')
cityid_pattern = re.compile('cityid\((.*?),(.*?)\)')
placeid_pattern = re.compile('placeid\((.*?)\)')
if __name__ == '__main__':
test_dat... | 2,100 | 26.644737 | 54 | py |
Unimer | Unimer-master/grammars/geo/lambda_calculus_grammar.py | # coding=utf8
ROOT_RULE = 'statement -> [expression]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['(expression ws)']
GRAMMAR_DICTIONARY['expression'] = ['(application)', '(abstraction)', '(constant)', '(variable)']
GRAMMAR_DICTIONARY['abstraction'] = ['("(" ws "lambda" wsp variable_definition wsp expre... | 5,431 | 77.724638 | 901 | py |
Unimer | Unimer-master/grammars/geo/geo_tokenizer.py | # coding=utf8
from typing import List
from overrides import overrides
from allennlp.data.tokenizers import Token, WordTokenizer
from allennlp.data.tokenizers.word_splitter import WordSplitter
class FunQLWordSplitter(WordSplitter):
@overrides
def split_words(self, logical_form: str) -> List[Token]:
no... | 6,678 | 31.740196 | 128 | py |
Unimer | Unimer-master/grammars/geo/geo_normalization.py | # coding=utf8
import re
def anonymize_prolog_variable_names(logical_form):
p = re.sub('[A-G]', 'A', logical_form).lower()
return p
def tokenize_prolog(logical_form):
# Tokenize Prolog
normalized_lf = logical_form.replace(" ", "::")
replacements = [
('(', ' ( '),
(')', ' ) '),
... | 2,678 | 27.2 | 113 | py |
Unimer | Unimer-master/grammars/geo/get_prolog_terminals.py | # coding=utf8
import re
stateid_pattern = re.compile('_stateid\((.*?)\)')
riverid_pattern = re.compile('_riverid\((.*?)\)')
countryid_pattern = re.compile('_countryid\((.*?)\)')
cityid_pattern = re.compile('_cityid\((.*?),(.*?)\)')
placeid_pattern = re.compile('_placeid\((.*?)\)')
if __name__ == '__main__':
tes... | 2,182 | 28.106667 | 89 | py |
Unimer | Unimer-master/grammars/geo/funql_grammar.py | # coding=utf-8
"""
FunQL Grammar
"""
import copy
from typing import List, Dict
from pprint import pprint
from parsimonious.exceptions import ParseError
from parsimonious.grammar import Grammar as _Grammar
# First-order logical form
ROOT_RULE = 'statement -> [answer]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['stat... | 9,398 | 63.82069 | 492 | py |
Unimer | Unimer-master/grammars/geo/lambda_calculus_grammar_2.py | # coding=utf8
ROOT_RULE = 'statement -> [expression]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['(expression ws)']
GRAMMAR_DICTIONARY['expression'] = ['(application)', '(abstraction)', '(constant)', '(variable)']
GRAMMAR_DICTIONARY['abstraction'] = ['("(" ws "lambda" wsp variable_definition wsp expre... | 5,675 | 72.714286 | 922 | py |
Unimer | Unimer-master/grammars/geo/get_sql_terminals.py | # coding=utf8
import os
import re
import pandas as pd
from pprint import pprint
number_pattern = re.compile('[+-]?([0-9]*[.])?[0-9]+')
if __name__ == '__main__':
path = '../../data/geo/sql_data'
terminals = set()
terminal_dict = dict()
for filename in os.listdir(path):
table_name = filename.... | 1,456 | 32.113636 | 76 | py |
Unimer | Unimer-master/grammars/geo/typed_prolog_grammar.py | # codinng=utf8
ROOT_RULE = 'statement -> ["answer(" Var "," Form ")"]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['("answer(" Var "," Form ")")']
# Variable
GRAMMAR_DICTIONARY['Var'] = ['"a"', '"b"', '"c"',
'"d"', '"e"', '"f"', '"g"', '"nv"', '"v0"', '"v1"', '"v2"',
... | 4,619 | 51.5 | 450 | py |
Unimer | Unimer-master/grammars/geo/__init__.py | # coding=utf-8 | 14 | 14 | 14 | py |
Unimer | Unimer-master/grammars/geo/prolog_grammar.py | # coding=utf-8
"""
Prolog Grammar
"""
import copy
from typing import List, Dict
from pprint import pprint
from parsimonious.exceptions import ParseError
from parsimonious.grammar import Grammar as _Grammar
# First-order logical form
ROOT_RULE = 'statement -> ["answer(" var "," goal ")"]'
GRAMMAR_DICTIONARY = {}
GRAM... | 7,194 | 42.083832 | 450 | py |
Unimer | Unimer-master/grammars/geo/geo_gnn_entity_matcher.py | # coding=utf8
import re
import os
import copy
import json
import numpy as np
from nltk.corpus import stopwords
from typing import List, Dict
from overrides import overrides
from allennlp.data.tokenizers import Token, WordTokenizer
from allennlp.data.tokenizers.word_splitter import SpacyWordSplitter
from .geo_entity_ex... | 13,433 | 41.920128 | 123 | py |
Unimer | Unimer-master/grammars/geo/sql_grammar_3.py | # coding=utf8
ROOT_RULE = 'statement -> [mquery]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY["statement"] = ['(mquery ws)']
GRAMMAR_DICTIONARY["mquery"] = ['(select_core ws)']
# SELECT
GRAMMAR_DICTIONARY["select_core"] = [
'(select_with_distinct ws select_results ws from_clause ws where_clause)',
'(select_w... | 8,959 | 53.969325 | 502 | py |
Unimer | Unimer-master/grammars/geo/typed_funql_grammar.py | # coding=utf8
"""
Typed Prolog Grammar
"""
ROOT_RULE = 'statement -> [Query]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['(Query ws)']
GRAMMAR_DICTIONARY['Query'] = [
'("answer(" City ")")',
'("answer(" Country ")")',
'("answer(" Num ")")',
'("answer(" Place ")")',
'("answer(" Sta... | 7,591 | 38.336788 | 491 | py |
Unimer | Unimer-master/grammars/geo/geo_entity_extractor.py | # coding=utf8
import os
from allennlp.data.tokenizers import Token, WordTokenizer
from allennlp.data.tokenizers.word_splitter import SpacyWordSplitter
def funql_entity_extractor(grammar, funql):
"""
:param grammar: FunQL grammar 1
:param funql:
:return:
"""
applied_production_rules = grammar.... | 12,755 | 36.517647 | 159 | py |
Unimer | Unimer-master/grammars/geo/sql_grammar_2.py | # coding=utf8
ROOT_RULE = 'statement -> [mquery]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY["statement"] = ['(mquery ws)']
GRAMMAR_DICTIONARY["mquery"] = ['(query ws)']
GRAMMAR_DICTIONARY["query"] = ['(ws select_core ws groupby_clause ws orderby_clause ws "limit 1")',
'(ws select_cor... | 9,005 | 57.480519 | 502 | py |
Unimer | Unimer-master/grammars/geo/sql_grammar.py | # coding=utf8
ROOT_RULE = 'statement -> [mquery]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY["statement"] = ['(mquery ws)']
GRAMMAR_DICTIONARY["mquery"] = [
'(ws select_clause ws from_clause ws where_clause ws groupby_clause ws having_clause ws orderby_clause ws limit)',
'(ws select_clause ws from_clause ws ... | 9,095 | 60.877551 | 563 | py |
Unimer | Unimer-master/grammars/geo/get_lambda_calculus_terminals.py | # coding=utf8
import re
state_pattern = re.compile('\s([a-z|_|.]+?:s)[\s|)]')
city_pattern = re.compile('\s([a-z|_|.]+?:c)[\s|)]')
river_pattern = re.compile('\s([a-z|_|.]+?:r)[\s|)]')
place_pattern = re.compile('\s([a-z|_|.]+?:p)[\s|)]')
lake_pattern = re.compile('\s([a-z|_|.]+?:l)[\s|)]')
location_pattern = re.comp... | 2,675 | 28.733333 | 63 | py |
Unimer | Unimer-master/grammars/atis/atis_sql_entity_matcher.py | # coding=utf8
import os
import re
import itertools
import collections
import numpy as np
from typing import List, Dict
from nltk.corpus import stopwords
from allennlp.data.tokenizers import Token
def clean_id(s, id_suffix, strip=None):
true_id = re.sub(' +', ' ', s)
if strip:
for v in strip:
... | 12,292 | 41.243986 | 110 | py |
Unimer | Unimer-master/grammars/atis/get_funql_terminals.py | # coding=utf8
def read_data():
questions, logical_forms = list(), list()
paths = [
"../../data/atis/atis_funql_train.tsv",
"../../data/atis/atis_funql_dev.tsv",
"../../data/atis/atis_funql_test.tsv"]
for p in paths:
with open(p, "r") as f:
for line in f:
... | 2,337 | 32.884058 | 90 | py |
Unimer | Unimer-master/grammars/atis/lambda_calculus_grammar.py | # coding=utf8
ROOT_RULE = 'statement -> [expression]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['(expression ws)']
GRAMMAR_DICTIONARY['expression'] = [
'(constant)', '(application)', '(abstraction)', '(variable)']
GRAMMAR_DICTIONARY['abstraction'] = [
'("(" ws "_lambda" wsp variable_definitio... | 13,149 | 68.210526 | 888 | py |
Unimer | Unimer-master/grammars/atis/atis_seq2seq_sql_entity_matcher.py | # coding=utf8
import os
import re
import itertools
import collections
import numpy as np
from typing import List, Dict
from nltk.corpus import stopwords
from allennlp.data.tokenizers import Token
def clean_id(s, id_suffix, strip=None):
true_id = re.sub(' +', ' ', s)
if strip:
for v in strip:
... | 10,128 | 39.678715 | 100 | py |
Unimer | Unimer-master/grammars/atis/lambda_calculus_grammar_3.py | # coding=utf8
ROOT_RULE = 'statement -> [expression]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['(expression ws)']
GRAMMAR_DICTIONARY['expression'] = [
'(constant)', '(application)', '(abstraction)', '(variable)']
GRAMMAR_DICTIONARY['abstraction'] = [
'("(" ws "_lambda" wsp variable_definitio... | 13,898 | 58.652361 | 564 | py |
Unimer | Unimer-master/grammars/atis/atis_lambda_calculus_entity_matcher.py | # coding=utf8
import os
import re
import itertools
import collections
import numpy as np
import pandas as pd
from typing import List, Dict
from allennlp.data.tokenizers import Token
def clean_id(s, id_suffix, strip=None):
true_id = s.replace(' ', '_')
if strip:
for v in strip:
true_id = t... | 12,328 | 39.960133 | 116 | py |
Unimer | Unimer-master/grammars/atis/get_prolog_terminals.py | # coding=utf8
import re
def read_data():
questions, logical_forms = list(), list()
paths = [
"../../data/atis/atis_prolog_train.tsv",
"../../data/atis/atis_prolog_dev.tsv",
"../../data/atis/atis_prolog_test.tsv"]
for p in paths:
with open(p, "r") as f:
for line... | 4,187 | 32.774194 | 104 | py |
Unimer | Unimer-master/grammars/atis/atis_tokenizer.py | # coding=utf8
from typing import List
from overrides import overrides
from allennlp.data.tokenizers import Token, WordTokenizer
from allennlp.data.tokenizers.word_splitter import WordSplitter
class FunQLWordSplitter(WordSplitter):
@overrides
def split_words(self, logical_form: str) -> List[Token]:
no... | 6,185 | 33.176796 | 369 | py |
Unimer | Unimer-master/grammars/atis/funql_grammar.py | # coding=utf8
"""
FunQL Grammar for ATIS
"""
ROOT_RULE = 'statement -> [answer]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['(answer ws)']
GRAMMAR_DICTIONARY['answer'] = ['("answer" ws "(" ws predicate ws ")" )']
GRAMMAR_DICTIONARY['predicate'] = [
'meta', 'object', 'collection', 'relation',
... | 21,561 | 67.234177 | 715 | py |
Unimer | Unimer-master/grammars/atis/atis_entity_matcher.py | # coding=utf8
import os
import re
import itertools
import collections
import numpy as np
from typing import List, Dict
from allennlp.data.tokenizers import Token
def clean_id(s, id_suffix, strip=None):
true_id = s.replace(' ', '_')
if strip:
for v in strip:
true_id = true_id.replace(v, ''... | 11,052 | 40.867424 | 110 | py |
Unimer | Unimer-master/grammars/atis/prolog_grammar_2.py | # coding=utf8
"""
Prolog Grammar of ATIS
"""
GRAMMAR_DICTIONARY = {}
ROOT_RULE = 'statement -> [answer]'
GRAMMAR_DICTIONARY['statement'] = ['(answer ws)']
GRAMMAR_DICTIONARY['answer'] = [
'("answer_1(" var "," Form ")")',
'("answer_2(" var "," var "," Form ")")',
'("answer_3(" var "," var "," var "," F... | 14,314 | 54.484496 | 715 | py |
Unimer | Unimer-master/grammars/atis/atis_seq2seq_lambda_calculus_entity_matcher.py | # coding=utf8
import os
import re
import itertools
import collections
import numpy as np
from typing import List
from allennlp.data.tokenizers import Token
def clean_id(s, id_suffix, strip=None):
true_id = s.replace(' ', '_')
if strip:
for v in strip:
true_id = true_id.replace(v, '').stri... | 10,685 | 38.431734 | 116 | py |
Unimer | Unimer-master/grammars/atis/atis_seq2seq_entity_matcher.py | # coding=utf8
import os
import re
import itertools
import collections
from typing import List
from allennlp.data.tokenizers import Token
def clean_id(s, id_suffix, strip=None):
true_id = s.replace(' ', '_')
if strip:
for v in strip:
true_id = true_id.replace(v, '').strip()
return '%s'... | 9,965 | 39.512195 | 107 | py |
Unimer | Unimer-master/grammars/atis/lambda_calculus_grammar_2.py | # coding=utf8
ROOT_RULE = 'statement -> [expression]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['(expression ws)']
GRAMMAR_DICTIONARY['expression'] = [
'(constant)', '(application)', '(abstraction)', '(variable)']
GRAMMAR_DICTIONARY['abstraction'] = [
'("(" ws "_lambda" wsp variable_definitio... | 13,179 | 67.290155 | 888 | py |
Unimer | Unimer-master/grammars/atis/get_atis_predicates.py | # coding=utf8
def read_data():
questions, logical_forms = list(), list()
paths = ["../../data/atis/atis_lambda_train.tsv",
"../../data/atis/atis_lambda_dev.tsv",
"../../data/atis/atis_lambda_test.tsv"]
for p in paths:
with open(p, "r") as f:
for line in f:
... | 1,850 | 27.045455 | 81 | py |
Unimer | Unimer-master/grammars/atis/prolog_grammar.py | # coding=utf8
"""
Prolog Grammar of ATIS
"""
GRAMMAR_DICTIONARY = {}
ROOT_RULE = 'statement -> [answer]'
GRAMMAR_DICTIONARY['statement'] = ['(answer ws)']
GRAMMAR_DICTIONARY['answer'] = [
'("answer_1(" var "," goal ")")',
'("answer_2(" var "," var "," goal ")")',
'("answer_3(" var "," var "," var "," g... | 24,384 | 69.071839 | 715 | py |
Unimer | Unimer-master/grammars/atis/sql_grammar_3.py | # coding=utf8
ROOT_RULE = 'statement -> [mquery]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY["statement"] = ['(mquery ws)']
GRAMMAR_DICTIONARY["mquery"] = [
'(ws select_clause ws from_clause ws where_clause ws groupby_clause ws orderby_clause)',
'(ws select_clause ws from_clause ws where_clause ws groupby_cl... | 22,697 | 67.781818 | 493 | py |
Unimer | Unimer-master/grammars/atis/lambda_calculus_grammar_4.py | # coding=utf8
ROOT_RULE = 'statement -> [expression]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['(expression ws)']
GRAMMAR_DICTIONARY['expression'] = [
'(constant)', '(application)', '(abstraction)', '(variable)']
GRAMMAR_DICTIONARY['abstraction'] = [
'("(" ws "_lambda" wsp variable_definitio... | 12,429 | 52.347639 | 130 | py |
Unimer | Unimer-master/grammars/atis/typed_funql_grammar.py | # coding=utf8
"""
Typed FunQL Grammar
Non-Terminals are Type of object
Each predicate is categoried based on what they return
"""
ROOT_RULE = 'statement -> [Query]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['(Query ws)']
GRAMMAR_DICTIONARY['Query'] = [
'("answer(" Predicate ")")'
]
GRAMMAR_DICT... | 14,870 | 45.327103 | 715 | py |
Unimer | Unimer-master/grammars/atis/atis_gnn_entity_matcher.py | # coding=utf8
import os
import re
import copy
import itertools
import collections
import numpy as np
from overrides import overrides
from typing import List, Dict
from allennlp.data.tokenizers import Token, WordTokenizer
from allennlp.data.tokenizers.word_splitter import SpacyWordSplitter
from .atis_entity_extractor i... | 18,309 | 38.040512 | 116 | py |
Unimer | Unimer-master/grammars/atis/sql_grammar_2.py | # coding=utf8
ROOT_RULE = 'statement -> [mquery]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY["statement"] = ['(mquery ws)']
GRAMMAR_DICTIONARY["mquery"] = [
'(ws select_clause ws from_clause ws where_clause ws groupby_clause ws orderby_clause)',
'(ws select_clause ws from_clause ws where_clause ws groupby_cl... | 22,265 | 69.462025 | 493 | py |
Unimer | Unimer-master/grammars/atis/sql_grammar.py | # coding=utf8
ROOT_RULE = 'statement -> [mquery]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY["statement"] = ['(mquery ws)']
GRAMMAR_DICTIONARY["mquery"] = [
'(ws select_clause ws from_clause ws where_clause ws groupby_clause ws orderby_clause)',
'(ws select_clause ws from_clause ws where_clause ws groupby_cl... | 12,125 | 93.734375 | 1,617 | py |
Unimer | Unimer-master/grammars/atis/atis_normalization.py | # coding=utf8
import re
def standardize_lambda_calculus_varnames(ans):
toks = ans.split(' ')
varnames = {}
new_toks = []
for t in toks:
if t == 'x' or t.startswith('$'):
if ':' in t:
# var definition
splits = t.split(':')
name, var_... | 6,133 | 29.979798 | 114 | py |
Unimer | Unimer-master/grammars/atis/atis_entity_extractor.py | # coding=utf8
from allennlp.data import Token
def lambda_calculus_entity_extractor(grammar, lc):
"""
:param grammar: Lambda Calculus Grammar 1
:param prolog:
:return:
"""
applied_production_rules = grammar.parse(lc)
entities = set()
for rule in applied_production_rules:
if rule... | 5,921 | 35.109756 | 187 | py |
Unimer | Unimer-master/grammars/job/job_tokenizer.py | # coding=utf8
from typing import List
from overrides import overrides
from allennlp.data.tokenizers import Token, WordTokenizer
from allennlp.data.tokenizers.word_splitter import WordSplitter
class PrologWordSplitter(WordSplitter):
@overrides
def split_words(self, logical_form: str) -> List[Token]:
n... | 4,463 | 30.216783 | 125 | py |
Unimer | Unimer-master/grammars/job/get_prolog_terminals.py | # coding=utf8
import re
def read_data():
questions, logical_forms = list(), list()
paths = [
"../../data/job/job_prolog_train.tsv",
"../../data/job/job_prolog_test.tsv"]
for p in paths:
with open(p, "r") as f:
for line in f:
line = line.strip()
... | 2,823 | 31.090909 | 120 | py |
Unimer | Unimer-master/grammars/job/funql_grammar.py | # coding=utf8
"""
FunQL Grammar
"""
ROOT_RULE = 'statement -> [answer]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['(answer ws)']
GRAMMAR_DICTIONARY['answer'] = ['("answer" ws "(" ws predicate ws ")" )']
GRAMMAR_DICTIONARY['predicate'] = [
'meta', 'object', '"job(all)"', 'relation',
'("inter... | 4,627 | 69.121212 | 2,343 | py |
Unimer | Unimer-master/grammars/job/get_sql_terminals.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/grammars/job/lambda_grammar.py | # coding=utf8
ROOT_RULE = 'statement -> [expression]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['(expression ws)']
GRAMMAR_DICTIONARY['expression'] = ['(application)', '(abstraction)', '(constant)', '(variable)']
GRAMMAR_DICTIONARY['abstraction'] = ['("(" ws "lambda" wsp variable_definition wsp expre... | 4,561 | 86.730769 | 2,273 | py |
Unimer | Unimer-master/grammars/job/__init__.py | 0 | 0 | 0 | py | |
Unimer | Unimer-master/grammars/job/prolog_grammar.py | # coding=utf-8
"""
Prolog Grammar
"""
# First-order logical form
ROOT_RULE = 'statement -> ["answer(" var "," goal ")"]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY['statement'] = ['("answer(" var "," goal ")")']
# Goal
GRAMMAR_DICTIONARY['goal'] = [
'(declaration)',
'(binary_relation)',
'(unit_relation)'... | 5,427 | 64.39759 | 2,343 | py |
Unimer | Unimer-master/grammars/job/job_normalization.py | # coding=utf8
import re
def tokenize_prolog(logical_form):
# Tokenize Prolog
normalized_lf = logical_form.replace(" ", "::")
replacements = [
('(', ' ( '),
(')', ' ) '),
(',', ' , '),
("\\+", " \\+ "),
]
for a, b in replacements:
normalized_lf = normalized_... | 3,371 | 31.114286 | 120 | py |
Unimer | Unimer-master/grammars/job/sql_grammar.py | # coding=utf8
ROOT_RULE = 'statement -> [mquery]'
GRAMMAR_DICTIONARY = {}
GRAMMAR_DICTIONARY["statement"] = ['(mquery ws)']
GRAMMAR_DICTIONARY["mquery"] = [
'(ws select_clause ws from_clause ws where_clause)',
'(ws select_clause ws from_clause)'
]
# SELECT
GRAMMAR_DICTIONARY["select_clause"] = [
'("sele... | 5,376 | 83.015625 | 2,746 | py |
seld-dcase2023 | seld-dcase2023-main/visualize_seldnet_output.py | #
# A wrapper script that trains the SELDnet. The training stops when the early stopping metric - SELD error stops improving.
#
import numpy as np
import os
import sys
import cls_data_generator
import seldnet_model
import parameters
import torch
from IPython import embed
import matplotlib
matplotlib.use('Agg')
#matplot... | 5,100 | 41.157025 | 133 | py |
seld-dcase2023 | seld-dcase2023-main/batch_feature_extraction.py | # Extracts the features, labels, and normalizes the development and evaluation split features.
import cls_feature_class
import parameters
import sys
def main(argv):
# Expects one input - task-id - corresponding to the configuration given in the parameter.py file.
# Extracts features and labels relevant for t... | 998 | 28.382353 | 102 | py |
seld-dcase2023 | seld-dcase2023-main/cls_feature_class.py | # Contains routines for labels creation, features extraction and normalization
#
import os
import numpy as np
import scipy.io.wavfile as wav
from sklearn import preprocessing
import joblib
from IPython import embed
import matplotlib.pyplot as plot
import librosa
plot.switch_backend('agg')
import shutil
import math
im... | 32,805 | 49.238897 | 155 | py |
seld-dcase2023 | seld-dcase2023-main/cls_data_generator.py | #
# Data generator for training the SELDnet
#
import os
import numpy as np
import cls_feature_class
from IPython import embed
from collections import deque
import random
class DataGenerator(object):
def __init__(
self, params, split=1, shuffle=True, per_file=False, is_eval=False
):
self._... | 13,414 | 44.941781 | 172 | py |
seld-dcase2023 | seld-dcase2023-main/parameters.py | # Parameters used in the feature extraction, neural network model, and training the SELDnet can be changed here.
#
# Ideally, do not change the values of the default parameters. Create separate cases with unique <task-id> as seen in
# the code below (if-else loop) and use them. This way you can easily reproduce a confi... | 5,433 | 37.267606 | 130 | py |
seld-dcase2023 | seld-dcase2023-main/seldnet_model.py | # The SELDnet architecture
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import math
from IPython import embed
class MSELoss_ADPIT(object):
def __init__(self):
super().__init__()
self._each_loss = nn.MSELoss(reduction='none')
def _each_calc(self, outpu... | 9,178 | 48.085561 | 215 | py |
seld-dcase2023 | seld-dcase2023-main/train_seldnet.py | #
# A wrapper script that trains the SELDnet. The training stops when the early stopping metric - SELD error stops improving.
#
import os
import sys
import numpy as np
import matplotlib.pyplot as plot
import cls_feature_class
import cls_data_generator
import seldnet_model
import parameters
import time
from time import... | 22,604 | 55.5125 | 369 | py |
seld-dcase2023 | seld-dcase2023-main/SELD_evaluation_metrics.py | # Implements the localization and detection metrics proposed in [1] with extensions to support multi-instance of the same class from [2].
#
# [1] Joint Measurement of Localization and Detection of Sound Events
# Annamaria Mesaros, Sharath Adavanne, Archontis Politis, Toni Heittola, Tuomas Virtanen
# WASPAA 2019
#
# [2]... | 13,630 | 48.930403 | 215 | py |
seld-dcase2023 | seld-dcase2023-main/cls_compute_seld_results.py | import os
import SELD_evaluation_metrics
import cls_feature_class
import parameters
import numpy as np
from scipy import stats
from IPython import embed
def jackknife_estimation(global_value, partial_estimates, significance_level=0.05):
"""
Compute jackknife statistics from a global value and partial estimates... | 12,633 | 54.170306 | 324 | py |
api | api-master/api/DBFunctions.py | import psycopg2
import time
from configparser import ConfigParser
config = ConfigParser()
config.read ('credentials.ini')
class pgdb:
def __init__(self):
self.connect()
def connect(self):
DB_PASSWORD = config.get('database','password')
DB_USER = config.get('database','user')
... | 1,008 | 24.225 | 122 | py |
api | api-master/api/Helpers.py | from collections import defaultdict
import requests
import json
import DBFunctions
def LooksLikeInt(s):
try:
int(s)
return True
except ValueError:
return False
def base36encode(number, alphabet='0123456789abcdefghijklmnopqrstuvwxyz'):
"""Converts an integer to a base36 string."""
... | 2,063 | 27.666667 | 116 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.