コード例 #1
0
def segmentWords(query, unigramCost):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(SegmentationProblem(query, unigramCost))

    # (Retorna a juncao das palavras guarda em acoes, caso tenha alguma palavra)
    if ( len(ucs.actions) > 0 ): return ' '.join(ucs.actions)
    else: return query
コード例 #2
0
def insertVowels(queryWords, bigramCost, possibleFills):
    # BEGIN_YOUR_CODE (our solution is 3 lines of code, but don't worry if you deviate from this)
    if len(queryWords) == 0:
        return ''
    else:
        queryWords.insert(0, wordsegUtil.SENTENCE_BEGIN)
    ucs = util.UniformCostSearch(verbose=1)
    ucs.solve(VowelInsertionProblem(queryWords, bigramCost, possibleFills))
    words = ' '.join(ucs.actions)
    return words
コード例 #3
0
def segmentWords(query, unigramCost):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(SegmentationProblem(query, unigramCost))

    # BEGIN_YOUR_CODE (our solution is 3 lines of code, but don't worry if you deviate from this)
    words = ' '.join(ucs.actions)
    return words
コード例 #4
0
ファイル: submission.py プロジェクト: tsamying/cs221
def segmentAndInsert(query, bigramCost, possibleFills):
    if len(query) == 0:
        return ''

    # BEGIN_YOUR_CODE (our solution is 4 lines of code, but don't worry if you deviate from this)
    ucs = util.UniformCostSearch(verbose=1)
    ucs.solve(
        JointSegmentationInsertionProblem(query, bigramCost, possibleFills))
    words = ' '.join(ucs.actions)
    return words
コード例 #5
0
def segmentWords(query, unigramCost):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(SegmentationProblem(query, unigramCost))

    if (len(ucs.actions) > 0):
        return ' '.join(ucs.actions)
    else:
        return query
コード例 #6
0
ファイル: submission.py プロジェクト: yapdianang/AI
def insertVowels(queryWords, bigramCost, possibleFills):
    # BEGIN_YOUR_CODE (our solution is 3 lines of code, but don't worry if you deviate from this)
    if len(queryWords) == 0:
        return ''
    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(VowelInsertionProblem(queryWords, bigramCost, possibleFills))
    #setence = []
    #for word in ucs.actions:
    #    setence.append(word)
    #return ' '.join(setence)
    return ' '.join(ucs.actions)
コード例 #7
0
ファイル: submission_v2.py プロジェクト: anatu/CS221-Fall2018
def insertVowels(queryWords, bigramCost, possibleFills):
    # BEGIN_YOUR_CODE (our solution is 3 lines of code, but don't worry if you deviate from this)
    if len(queryWords) == 0:
    	return ""

    ucs = util.UniformCostSearch(verbose = 1)
    ucs.solve(VowelInsertionProblem(queryWords, bigramCost, possibleFills))
    if ucs.actions != None:
        return " ".join(ucs.actions)
    else:
        return " ".join(queryWords)
コード例 #8
0
def segmentWords(query, unigramCost):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(SegmentationProblem(query, unigramCost))
    
    # BEGIN_YOUR_CODE (solucao em 3 linhas de codigo, mas utilize quantas linhas julgar necessario)
    if(len(ucs.actions) > 0):
        return ' '.join(ucs.actions)
    else: return query
コード例 #9
0
def segmentWords(query, unigramCost):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(SegmentationProblem(query, unigramCost))

    answer = query
    if (len(ucs.actions)):
        answer = ' '.join(ucs.actions)

    return answer
コード例 #10
0
def segmentAndInsert(query, bigramCost, possibleFills):
    if len(query) == 0:
        return ''

    # BEGIN_YOUR_CODE (solucao em 4 linhas de codigo, mas utilize quantas linhas julgar necessario)
    prob = JointSegmentationInsertionProblem(query,bigramCost,possibleFills)
    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(prob)
    results = []
    for word in ucs.actions:
    	results.append(word)
    return ' '.join(results)
コード例 #11
0
def testNonTrivialHeuristic():
    # Make sure putting a non-trivial heuristic in does not change the solution.
    problem = util.trivialProblem
    heuristic = util.trivialProblemHeuristic
    ucs = util.UniformCostSearch()
    astar = submission.AStarSearch(heuristic)
    ucs.solve(problem)
    astar.solve(problem)
    if ucs.actions == astar.actions and ucs.totalCost == astar.totalCost:
        grader.assignFullCredit()
    else:
        grader.fail("Reduced problem has different solution!")
コード例 #12
0
def segmentWords(query, unigramCost):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(SegmentationProblem(query, unigramCost))

    # BEGIN_YOUR_CODE (around 3 lines of code expected)
    if (len(ucs.actions) > 0):
        return ' '.join(ucs.actions)
    else:
        return query
コード例 #13
0
def segmentAndInsert(query, bigramCost, possibleFills):
    if len(query) == 0:
        return ''

    # BEGIN_YOUR_CODE (around 5 lines of code expected)
    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(
        JointSegmentationInsertionProblem(query, bigramCost, possibleFills))
    if (ucs.actions is not None):
        return ' '.join(ucs.actions)
    else:
        return ''
コード例 #14
0
def segmentAndInsert(query, bigramCost, possibleFills):
    if len(query) == 0:
        return ''

    # BEGIN_YOUR_CODE (our solution is 4 lines of code, but don't worry if you deviate from this)
    #raise Exception("Not implemented yet")
    print("Query is " + str(query))
    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(
        JointSegmentationInsertionProblem(query, bigramCost, possibleFills))
    print("Result is " + str(ucs.actions))
    return ' '.join(ucs.actions)
コード例 #15
0
def segmentAndInsert(query, bigramCost, possibleFills):
    if len(query) == 0:
        return ''

    # BEGIN_YOUR_CODE (around 5 lines of code expected)
    problem = JointSegmentationInsertionProblem(query, bigramCost,
                                                possibleFills)
    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(problem)
    result = []
    for word in ucs.actions:
        result.append(word)
    return ' '.join(result)
コード例 #16
0
def segmentAndInsert(query, bigramCost, possibleFills):
    if len(query) == 0:
        return ''

    # BEGIN_YOUR_CODE (around 5 lines of code expected)
    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(
        JointSegmentationInsertionProblem(query, bigramCost, possibleFills))

    print "segmentandinsert"
    print "here are the results:"
    print ucs.actions
    return ' '.join(ucs.actions)
コード例 #17
0
    def solve(self, problem):
        # Reduce the |problem| to |newProblem|, which is solved by UCS.
        newProblem = astarReduction(problem, self.heuristic)
        algorithm = util.UniformCostSearch()
        algorithm.solve(newProblem)

        # Copy solution back
        self.actions = algorithm.actions
        if algorithm.totalCost != None:
            self.totalCost = algorithm.totalCost + self.heuristic(
                problem.startState())
        else:
            self.totalCost = None
        self.numStatesExplored = algorithm.numStatesExplored
コード例 #18
0
def segmentAndInsert(query, bigramCost, possibleFills):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(
        JointSegmentationInsertionProblem(query, bigramCost, possibleFills))

    answer = query
    if ucs.actions is None:
        return answer
    elif (len(ucs.actions)):
        answer = ' '.join(ucs.actions)
    return answer
コード例 #19
0
def segmentWords(query, unigramCost):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(SegmentationProblem(query, unigramCost))

    # BEGIN_YOUR_CODE (our solution is 10 lines of code, but don't worry if you deviate from this)
    actions = ucs.actions
    actions.insert(0, -1)
    words = []
    for i in range(len(actions) - 1):
        words.append(query[actions[i] + 1:actions[i + 1] + 1])
    return ' '.join(words)
コード例 #20
0
ファイル: submission.py プロジェクト: chenqinlian/CS221
def insertVowels(queryWords, bigramCost, possibleFills):
    # BEGIN_YOUR_CODE (our solution is 3 lines of code, but don't worry if you deviate from this)
    # raise Exception("Not implemented yet")
    if len(queryWords) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(VowelInsertionProblem(queryWords, bigramCost, possibleFills))

    if len(ucs.actions) > 0:
        #print 'Problem 2-b: ', ' '.join(ucs.actions)
        return ' '.join(ucs.actions)
    else:
        return ''
コード例 #21
0
ファイル: submission.py プロジェクト: yapdianang/AI
def segmentWords(query, unigramCost):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(SegmentationProblem(query, unigramCost))

    # BEGIN_YOUR_CODE (our solution is 3 lines of code, but don't worry if you deviate from this)
    words = []
    state = 0
    for i in ucs.actions:
        words.append(query[state:(state + i)])
        state = state + i
    return ' '.join(words)
コード例 #22
0
ファイル: submission.py プロジェクト: henrique010/ia
def segmentAndInsert(query, bigramCost, possibleFills):
    if len(query) == 0:
        return ''

    # BEGIN_YOUR_CODE (solucao em 4 linhas de codigo, mas utilize quantas linhas julgar necessario)
    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(
        JointSegmentationInsertionProblem(query, bigramCost, possibleFills))
    if (ucs.actions is not None):
        return ' '.join(ucs.actions)
    else:
        return ''

    raise Exception("Not implemented yet")
コード例 #23
0
ファイル: submission.py プロジェクト: chenqinlian/CS221
def segmentWords(query, unigramCost):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(SegmentationProblem(query, unigramCost))

    # BEGIN_YOUR_CODE (our solution is 3 lines of code, but don't worry if you deviate from this)
    # raise Exception("Not implemented yet")
    if len(ucs.actions) > 0:
        #print 'Problem 1-b: ', ' '.join(ucs.actions)
        return ' '.join(ucs.actions)

    else:
        return ''
コード例 #24
0
def segmentWords(query, unigramCost):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(SegmentationProblem(query, unigramCost))

    # BEGIN_YOUR_CODE (around 5 lines of code expected)
    state = 0
    words = []
    for i in ucs.actions:
        word = query[state:state + i]
        state = state + i
        words.append(word)
    return ' '.join(words)
コード例 #25
0
ファイル: pathproblem.py プロジェクト: jakekim1009/cs221
def main():
    AANode = Node('AA', 0, 0, ['AB', 'BA'])
    #AB->BC is possible!
    ABNode = Node('AB', 1, 0, ['AA', 'BB','AC','BC'])
    ACNode = Node('AC', 2, 0, ['AB', 'BC'])
    BANode = Node('BA', 0, 1, ['AA', 'BB','CA'])
    BBNode = Node('BB', 1, 1, ['AB', 'BA','CB','BC'])
    BCNode = Node('BC', 2, 1, ['AC', 'CC','BB'])
    CANode = Node('CA', 0, 2, ['BA', 'CB'])
    CBNode = Node('CB', 1, 2, ['CA', 'BB','CC'])
    CCNode = Node('CC', 2, 2, ['BC', 'CB'])
    NodeMap = {'AA':AANode, 'AB':ABNode, 'AC':ACNode, 'BA':BANode, 'BB':BBNode, 'BC':BCNode, 'CA':CANode, 'CB':CBNode, 'CC':CCNode}
    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(PathProblem('AA','CC',NodeMap))
    actions = ucs.actions
    print actions
コード例 #26
0
def insertVowels(queryWords, bigramCost, possibleFills):
    # BEGIN_YOUR_CODE (around 5 lines of code expected)
    if len(queryWords) == 0:
        return ''

    potential_single_word_input = possibleFills(queryWords[0])

    if len(queryWords) == 1 and not potential_single_word_input:
        return queryWords[0]
    else:
        ucs = util.UniformCostSearch(verbose=0)
        ucs.solve(VowelInsertionProblem(queryWords, bigramCost, possibleFills))

        print "here are the results:"
        print ucs.actions
        return ' '.join(ucs.actions)
コード例 #27
0
def insertVowels(queryWords, bigramCost, possibleFills):

    if queryWords is None:
        return ''
    if len(queryWords) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(VowelInsertionProblem(queryWords, bigramCost, possibleFills))

    answer = ' '.join(queryWords)
    if ucs.actions is None:
        return answer
    elif (len(ucs.actions)):
        answer = ' '.join(ucs.actions)
    return answer
コード例 #28
0
ファイル: pathproblem_sw.py プロジェクト: jungsw/cs221
def main():

    inputFile = open('traffic_result.csv', 'r')
    NodeMap = {}
    result = {}
    crimemap = processTrain()

    for line in inputFile.readlines():
        if line[0] == ',': continue

        s1 = line.split('|')[0].split(',')
        sKey = (s1[1], s1[2])

        s2 = line.split('|')[-1].split(',')
        latLng = (float(s2[-2]), float(s2[-1].replace('\n', '')))
        #print latLng
        adjacentList = []
        for x, y in zip(*[iter(s2[0:-2])] * 2):
            x = x.replace('"', '')
            y = y.replace('"', '')
            adjacentList.append((x.strip(), y.strip()))

        crimeOccurrence = crimesAt(latLng[0], latLng[1], 0.00325016538,
                                   0.00325016538, crimemap)

        NodeMap[sKey] = Node(sKey, latLng, adjacentList, crimeOccurrencd)

    #print NodeMap

    #AANode = Node('AA', (0, 0), ['AB', 'BA'])
    #AB->BC is possible!
    #ABNode = Node('AB', (1, 0), ['AA', 'BB','AC','BC'])
    #ACNode = Node('AC', (2, 0), ['AB', 'BC'])
    #BANode = Node('BA', (0, 1), ['AA', 'BB','CA'])
    #BBNode = Node('BB', (1, 1), ['AB', 'BA','CB','BC'])
    #BCNode = Node('BC', (2, 1), ['AC', 'CC','BB'])
    #CANode = Node('CA', (0, 2), ['BA', 'CB'])
    #CBNode = Node('CB', (1, 2), ['CA', 'BB','CC'])
    #CCNode = Node('CC', (2, 2), ['BC', 'CB'])
    #NodeMap = {'AA':AANode, 'AB':ABNode, 'AC':ACNode, 'BA':BANode, 'BB':BBNode, 'BC':BCNode, 'CA':CANode, 'CB':CBNode, 'CC':CCNode}
    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(
        PathProblem(('EDDY ST', 'POLK ST'), ('GEARY ST', 'MASON ST'), NodeMap))
    actions = ucs.actions
    print actions
コード例 #29
0
ファイル: sentInUcs.py プロジェクト: yhjw88/deepreader
def InsertSentences(sentences, para, cost, costData):
    if len(para) == 0:
        return ''
    ucs = util.UniformCostSearch(verbose=0)
    sentences.append(None)
    ucs.solve(InsertionProblem(sentences, para, cost, costData))
    newpara=[]
    start=0
    newpara.append(str(para[0]))
    for e in ucs.actions:
        if e==None:
            start+=1
            newpara.append(para[start])
        else:
            newpara.append(e)
    lastindex=para.index(newpara[-1])
    if lastindex!=len(para)-1:
        newpara=newpara+para[lastindex+1:]
    return [str(v) for v in newpara]
コード例 #30
0
def segmentWords(query, unigramCost):
    if len(query) == 0:
        return ''

    ucs = util.UniformCostSearch(verbose=0)
    ucs.solve(SegmentationProblem(query, unigramCost))

    # BEGIN_YOUR_CODE (solucao em 3 linhas de codigo, mas utilize quantas linhas julgar necessario)
    #aqui eu pego cada palavra e jogo em uma variavel auxiliar, depois jogo na lista de palavras para ficar um vetor , e depois formulo a frase 
    state = 0
    words = []
    for i in ucs.actions:

    	word = query[state:state + i]

    	
    	state = state + i
    	words.append(word)
    return ' '.join(words)