Пример #1
0
def main():
    if len(argv) == 1:
        usage()

    if argv[1] == 'get':
        if len(argv) == 2:
            get()
        elif argv[2] in ['ubuntu', 'fedora', 'debian', 'arch']:
            get(argv[2])
        else:
            usage()
    elif argv[1] == 'add':
        try:
            libc_file = argv[2]
            add_local_libc(libc_file)
        except:
            usage()
    elif argv[1] == 'find':
        try:
            fun_name = argv[2]
            fun_addr = argv[3]
            find(fun_name, fun_addr)
        except:
            usage()
    elif argv[1] == 'identify':
        try:
            libc_file = argv[2]
            identify(libc_file)
        except:
            usage()
    elif argv[1] == 'status':
        status()
    else:
        usage()
def compute_subitized_complex(subrange, mmap, nterm):
    twos = len(find(mmap, 1))
    threes = len(find(mmap, 2))

    if twos == 1 and threes == 1:
        comp = nterm * 4 - 3
    elif twos == 1 and threes > 1:
        comp = nterm * 4 - 2
    elif twos > 1:
        comp = nterm * 4 - 1
    else:
        comp = nterm * 4

    return comp
    def eval(self, context: Context, pos, code):
        if not context.flags[GotoLine.flag]:
            new_pos = find(self.matching_line.re, code, pos, reverse=True)
            repeat_pos = new_pos - 1
            repeat_line = self.matching_line(get_line(code, repeat_pos))
            args = repeat_line.args
            index_var = repeat_line.index_var

            self.end.init(context, ForLine.end_name, repeat_pos,
                          exp_eval(args[1], context))
            if len(args) == 4:
                self.step.init(context, ForLine.step_name, repeat_pos,
                               exp_eval(args[2], context))
            else:
                self.step.init(context, ForLine.step_name, repeat_pos, 1)

            current = context.get_var(index_var)
            next_index = self.update_index(current, self.end.get(context),
                                           self.step.get(context))

            if next_index:
                context.set_var(
                    self.matching_line(get_line(code, new_pos - 1)).index_var,
                    next_index)
            else:
                return pos + 1

            return new_pos
        else:
            return pos + 1
Пример #4
0
def parsePrep(word, var, prop, string):
    rel = word.doc
    varToBeShown = []
    statement = ""
    replaceDictionary = {}

    isProp = None
    propVar = None

    if word.lemma_ == "of":
        for dep in findDependencies(word):
            if dep.dep_ == "pobj":
                if word.lemma_ == "as":
                    return {'property': dep}
                else:
                    var2 = gn.generateName()
                    var3 = gn.generateName()
                    res = parseNoun(dep, var3, prop)
                    varToBeShown += res["varToBeShown"]
                    statement += res["statement"]
                    replaceDictionary = concatDict(replaceDictionary,
                                                   res["replaceDictionary"])
                    isProp = True
                    propVar = var3
            elif dep.dep_ == "":
                pass
            else:
                raise ValueError
    else:
        replacements = find(string, True)

        if replacements == []:
            return parsePrepVerb(word, var)
        pobj = findDep(word, "pobj")
        var2 = gn.generateName()
        var3 = gn.generateName()
        res = parseNoun(pobj, var3, prop)
        varToBeShown += res["varToBeShown"]
        statement += res["statement"]
        replaceDictionary = concatDict(replaceDictionary,
                                       res["replaceDictionary"])
        isProp = True
        propVar = var3

    #else:
    #	raise ValueError

    return {
        "varToBeShown": varToBeShown,
        "statement": statement,
        "replaceDictionary": replaceDictionary,
        "isProp": isProp,
        "propVar": propVar
    }
Пример #5
0
def latesttracks(directory, days):
	"""
	Finds the latest additions to 'directory' (within the last 'days')
	and returns an XSPF playlist.
	"""
	tags = TagReader()
	then = time.time() - (days * 24 * 3600)
	date = time.strftime("%D", time.localtime(then))
	now  = time.strftime("%D")
	
	creator = "LatestXSPF"
	title = "New tracks from {date} till {now}".format(date=date, now=now)
	
	find(days=days, dir=directory, exts=[".mp3", ".flac", ".ogg"], hook=tags.read)
	
	print >> sys.stderr, len(tags), 'music files found'
	
	xspf = xspfgenerator.SimpleXSPFGenerator(title, creator)
	xspf.addTracks(tags.tags())
	return xspf
    def eval(self, context: Context, pos, code):
        if exp_eval(self.arg, context):
            pos += 1
        else:  # normally else or elseif will just jump to endif. this code prevents this by jumping past it.
            jmp_targets = (ElseIfLine, )
            re = r'(' + '|'.join(map(lambda x: x.re, jmp_targets)) + r')'

            while True:
                try:
                    pos = find(re, code, pos)
                    if get_line_instance(get_line(code, pos -
                                                  1)).get_condition(context):
                        return pos
                    else:
                        continue

                except FindError:
                    break

            pos = find(EndifLine.re, code, pos)

        return pos
Пример #7
0
def latesttracks(directory, days):
    """
	Finds the latest additions to 'directory' (within the last 'days')
	and returns an XSPF playlist.
	"""
    tags = TagReader()
    then = time.time() - (days * 24 * 3600)
    date = time.strftime("%D", time.localtime(then))
    now = time.strftime("%D")

    creator = "LatestXSPF"
    title = "New tracks from {date} till {now}".format(date=date, now=now)

    find(days=days,
         dir=directory,
         exts=[".mp3", ".flac", ".ogg"],
         hook=tags.read)

    print >> sys.stderr, len(tags), 'music files found'

    xspf = xspfgenerator.SimpleXSPFGenerator(title, creator)
    xspf.addTracks(tags.tags())
    return xspf
def compute_cost_comp(nnum, nterm, numberline, mus, c, w, need_probs,
                      subrange):
    F_i_w_numerator = compute_f_i_w_numerator(nnum, nterm, numberline, mus, c,
                                              w)
    F_i_w_numerator = np.multiply(F_i_w_numerator, need_probs)

    term_num_map = np.zeros((nterm, nnum))
    maxind = find(F_i_w_numerator, np.amax(F_i_w_numerator, 0), axis=1)
    maxmaxind = find(maxind, max(maxind))
    for i in range(maxmaxind[-1] + 1, len(maxind)):
        maxind[i] = max(maxind)

    for i in range(1, nterm - 1):
        inds = find(maxind, i)
        for ind in inds:
            term_num_map[i, ind] = 1

    for diff_ind in find_diff(numberline, find(sum(term_num_map), 1)):
        term_num_map[nterm - 1, diff_ind - 1] = 1

    mmap = np.argmax(term_num_map, 0)
    log_prob_L = np.zeros((1, nnum))

    for j in range(nterm):
        cat_inds = find(mmap, j)
        f = F_i_w_numerator[j, cat_inds]
        for ind in range(len(cat_inds)):
            log_prob_L[0, cat_inds[ind]] = (f[ind] / sum(f))
    log_prob_L = np.log2(log_prob_L)

    ccost_perm = np.sum(np.asarray(need_probs) * -log_prob_L[0])
    ccost_perm_ns = ccost_perm

    comp_perm = compute_subitized_complex(subrange, mmap, nterm)
    comp_perm_ns = 3 * len(find_unique(mmap))

    return ccost_perm, ccost_perm_ns, comp_perm, comp_perm_ns
Пример #9
0
def parsePrepVerb(p, var):
    statement = ""
    varToBeShown = []
    replaceDictionary = {}
    pobj = findDep(p, "pobj")
    if pobj == None:
        pobj = findDep(p, "pcomp")
    if pobj == None:
        return {
            "varToBeShown": varToBeShown,
            "statement": statement,
            "replaceDictionary": replaceDictionary
        }
    pobjv = gn.generateName()
    if pobj.pos_ != "NUM":
        res = parseNoun(pobj, pobjv, None)
        statement += res['statement']
        varToBeShown += res['varToBeShown']
        replaceDictionary = concatDict(replaceDictionary,
                                       res['replaceDictionary'])

        union = False
        for i in inProperties:
            prepVar = createName(i, True)
            replacements = find(i, True)
            if replacements != []:
                if union:
                    statement += " UNION "
                statement += "{" + var + " " + prepVar + " " + pobjv + ".}"
                replaceDictionary[prepVar] = ("wdt:", replacements)
                union = True
    return {
        "varToBeShown": varToBeShown,
        "statement": statement,
        "replaceDictionary": replaceDictionary
    }
Пример #10
0
def str2np(string):
    str_R = find(string, ']')
    i = 5
    return str_R
Пример #11
0
def generateStatements(word, combination, var, prop):
    sentence = word.doc.text
    sentence = sentence.replace(combination["string"],
                                combination["replacement"])
    rel = nlp(sentence)
    w = rel[combination["start"]]
    string = combination["string"]

    varToBeShown = []
    statement = ""
    replaceDictionary = {}

    isProp = None

    for dep in findDependencies(w):
        if dep.dep_ == "prep":
            if dep.i <= w.i:
                i = dep.i
            else:
                i = dep.i + combination["length"] - 1
            res = parsePrep(word.doc[i], var, prop, string)

            varToBeShown += res["varToBeShown"]
            statement += res["statement"]
            replaceDictionary = concatDict(replaceDictionary,
                                           res["replaceDictionary"])

            if isProp == None:
                if "isProp" in res and "propVar" in res:
                    isProp = res[
                        "isProp"]  #TODO: Check this for efficiency and properness
                    propVar = res["propVar"]
            elif isProp != res["isProp"]:
                raise ValueError
        elif dep.dep_ == "det":
            res = parseDet(dep, var)
            varToBeShown += res["varToBeShown"]
            statement += res["statement"]
            replaceDictionary = concatDict(replaceDictionary,
                                           res["replaceDictionary"])
        elif dep.dep_ == "acl":
            pass
        elif dep.dep_ == "amod":
            if dep.lemma_ != "all" or dep.lemma_ != "current":
                res = parseAmodAcomp(dep, var)
                varToBeShown += res["varToBeShown"]
                statement += res["statement"]
                replaceDictionary = concatDict(replaceDictionary,
                                               res["replaceDictionary"])
        else:
            raise ValueError

    if string.lower() in questionWords:
        selectVar = createSelectName(combination["start"])
        statement += "BIND(" + var + " AS " + selectVar + ").\n"
        #replaceDictionary[var] = selectVar
        varToBeShown.append(var)
        return {
            "varToBeShown": varToBeShown,
            "statement": statement,
            "replaceDictionary": replaceDictionary
        }
    if prop != None:
        isProp = True
        propVar = prop
    property = None
    if isProp == True:
        if string in countWords:
            statement1 = "SELECT (count(distinct " + propVar + ")  as " + var + ") WHERE {" + statement + "}\n"
            statement = statement1
        else:

            union = False
            cvar1 = gn.generateName()
            cvar2 = gn.generateName()
            coalesce = ""
            if find(string, True) != []:
                rvar = createName(string, True)
                replaceDictionary[rvar] = ("wdt:", find(string, True))
                statement += "OPTIONAL {" + propVar + " " + rvar + " " + cvar1 + "}"
                coalesce += "IF(BOUND(" + cvar1 + ")," + cvar1 + ",1/0)"
                union = True
            if find(string + " of", True) != []:
                if union:
                    coalesce += ", "
                coalesce += "IF(BOUND(" + cvar2 + ")," + cvar2 + ",1/0)"
                rvar = createName(string + " of", True)
                replaceDictionary[rvar] = ("wdt:", find(string + " of", True))
                statement += "OPTIONAL {" + cvar2 + " " + rvar + " " + propVar + "}"

            if find(string + " of", True) == [] and find(string, True) == []:
                raise ValueError

            statement += "BIND(COALESCE(" + coalesce + ") as " + var + ").\n"

            property = string

    elif find(string, False) != []:
        rvar = createName(string, False)
        replaceDictionary[rvar] = ("wd:", find(string, False))
        statement += "{ \n"
        statement += "BIND(" + rvar + " AS " + var + "). \n"
        statement += "} UNION { \n"
        statement += var + " wdt:P31 " + rvar + ". \n"
        statement += "}\n"
    else:
        rvar = createName(string, True)
        uvar = gn.generateName()
        replaceDictionary[rvar] = ("wdt:", find(string, True))
        statement += uvar + " " + rvar + " " + var
        if find(string, True) == []:
            raise ValueError

    return {
        "varToBeShown": varToBeShown,
        "statement": statement,
        "replaceDictionary": replaceDictionary,
        "property": property
    }
Пример #12
0
def compute_P_w_i_match_modemap(cluster, numberline, nterm, term_num_map,
                                mu_range, c, w, need_probs):
    nnum = len(numberline)
    mu_placements = list(itertools.combinations(mu_range, nterm))
    mu_placements = np.asarray(mu_placements)

    minmse = float("inf")
    best_P_w_i = None
    P_w_i_vec = None
    mus_match = None
    inds = []
    cvec = []

    for i in range(mu_placements.shape[0]):
        mus = mu_placements[i, :].reshape(-1, 1)
        P_w_i = compute_P_w_i(nnum, nterm, numberline, mus, c, w)
        maxPs = np.amax(P_w_i, axis=0)
        mode_cluster = np.argmax(P_w_i, axis=0)
        mode_cluster = [a + 1 for a in mode_cluster]

        mindiff = np.sum([abs(x - y) for x, y in zip(mode_cluster, cluster)])

        if mindiff < minmse:
            minmse = mindiff
            mus_match = mus
            P_w_i_vec = maxPs
            best_P_w_i = P_w_i

    for i in range(mu_placements.shape[0]):
        mus = mu_placements[i, :].reshape(-1, 1)
        P_w_i = compute_P_w_i(nnum, nterm, numberline, mus, c, w)
        maxPs = np.amax(P_w_i, axis=0)
        mode_cluster = np.argmax(P_w_i, axis=0)
        mode_cluster = [a + 1 for a in mode_cluster]

        if np.sum([abs(x - y)
                   for x, y in zip(mode_cluster, cluster)]) == mindiff:
            inds.append(i)
            F_i_w_numerator = compute_f_i_w_numerator(nnum, nterm, numberline,
                                                      mus, c, w)
            log_prob_L = np.zeros((1, nnum))

            for j in range(nterm):
                cat_inds = find(cluster, j + 1)
                cat_sum = 0
                for ind in cat_inds:
                    cat_sum += F_i_w_numerator[j, ind]
                for ind in cat_inds:
                    if cat_sum != 0:
                        log_prob_L[0, ind] = F_i_w_numerator[j, ind] / cat_sum
                    else:
                        log_prob_L[0, ind] = 0

            log_prob_L = np.log2(log_prob_L)
            cvec.append(sum((need_probs * -log_prob_L)[0]))

    ind = inds[find(cvec, min(cvec))[0]]
    mus_match = mu_placements[i, :]
    P_w_i = compute_P_w_i(nnum, nterm, numberline,
                          np.asarray(mus_match).reshape((-1, 1)), c, w)
    maxPs = np.amax(P_w_i)
    modeclust = np.argmax(P_w_i)

    return mus_match, P_w_i_vec
Пример #13
0
def extractRings(V, F, centerVIdx, numRings=1):
    VIdx = centerVIdx
    for ii in range(numRings):
        r, c = find(F, VIdx)
        VIdx = np.unique(F[r, :])
    return VIdx
Пример #14
0
 def eval(self, context: Context, pos, code):
     return find(WhileLine.re, code, pos, True) - 1
Пример #15
0
 def eval(self, context: Context, pos, code):
     if exp_eval(self.arg, context):
         return pos + 1
     else:
         return find(WendLine.re, code, pos)
Пример #16
0
 def eval(self, context: Context, pos, code):
     pos = find(EndifLine.re, code, pos)
     return pos