Exemple #1
0
def test_rangess():
    rss = rangess()
    assert len(rss) == 0

    rss.resize(5)
    assert len(rss) == 5
    for rs in rss:
        assert len(rs) == 0

    rss.clear()
    assert len(rss) == 0

    rs1 = ranges()
    rs1.append(range(1, 2))
    rs1.append(range(3, 4))

    rs2 = ranges()
    rs2.append(range(5, 6))
    rs2.append(range(7, 8))

    rss.extend([rs1, rs2])
    assert rss[0][0].begin == 1
    assert rss[0][1].begin == 3
    assert rss[1][0].begin == 5
    assert rss[1][1].begin == 7
    assert rss[0][0].end == 2
    assert rss[0][1].end == 4
    assert rss[1][0].end == 6
    assert rss[1][1].end == 8

    ser = pickle.dumps(rss, 2)
    deser = pickle.loads(ser)
    assert rss == deser
Exemple #2
0
def test_ranges():
    rs = ranges()
    assert len(rs) == 0

    rs.resize(5)
    assert len(rs) == 5
    for r in rs:
        assert r.begin == 0
        assert r.end == 0

    rs.clear()
    assert len(rs) == 0

    rs.extend([range(1, 2), range(3, 4)])
    assert rs[0].begin == 1
    assert rs[0].end == 2
    assert rs[1].begin == 3
    assert rs[1].end == 4

    ser = pickle.dumps(rs, 2)
    deser = pickle.loads(ser)
    assert rs == deser
Exemple #3
0
        else:
            vects.append(no_cap)
    return vects


def print_segment(sentence, names):
    words = sentence.split()
    for name in names:
        for i in name:
            sys.stdout.write(words[i] + " ")
        sys.stdout.write("\n")


# Now let's make some training data.  Each example is a sentence as well as a
# set of ranges which indicate the locations of any names.
names = dlib.ranges()  # make an array of dlib.range objects.
segments = dlib.rangess()  # make an array of arrays of dlib.range objects.
sentences = []

sentences.append("The other day I saw a man named Jim Smith")
# We want to detect person names.  So we note that the name is located within
# the range [8, 10).  Note that we use half open ranges to identify segments.
# So in this case, the segment identifies the string "Jim Smith".
names.append(dlib.range(8, 10))
segments.append(names)
names.clear()  # make names empty for use again below

sentences.append("Davis King is the main author of the dlib Library")
names.append(dlib.range(0, 2))
segments.append(names)
names.clear()
            vects.append(no_cap)
    return vects


def print_segment(sentence, names):
    words = sentence.split()
    for name in names:
        for i in name:
            sys.stdout.write(words[i] + " ")
        sys.stdout.write("\n")



# Now lets make some training data.  Each example is a sentence as well as a set of ranges
# which indicate the locations of any names.   
names = dlib.ranges()     # make an array of dlib.range objects.
segments = dlib.rangess() # make an array of arrays of dlib.range objects.
sentences = []


sentences.append("The other day I saw a man named Jim Smith")
# We want to detect person names.  So we note that the name is located within the
# range [8, 10).  Note that we use half open ranges to identify segments.  So in 
# this case, the segment identifies the string "Jim Smith".
names.append(dlib.range(8, 10))
segments.append(names)
names.clear() # make names empty for use again below


sentences.append("Davis King is the main author of the dlib Library")
names.append(dlib.range(0, 2))
Exemple #5
0
            vects.append(no_cap)
    return vects


def print_segment(sentence, names):
    words = sentence.split()
    for name in names:
        for i in name:
            sys.stdout.write(words[i] + " ")
        sys.stdout.write("\n")



# Now lets make some training data.  Each example is a sentence as well as a set of ranges
# which indicate the locations of any names.   
names = dlib.ranges()
segments = dlib.rangess()
sentences = []


sentences.append("The other day I saw a man named Jim Smith")
# We want to detect person names.  So we note that the name is located within the
# range [8, 10).  Note that we use half open ranges to identify segments.  So in 
# this case, the segment identifies the string "Jim Smith".
names.append(dlib.range(8, 10))
segments.append(names)
names.clear() # make names empty for use again below


sentences.append("Davis King is the main author of the dlib Library")
names.append(dlib.range(0, 2))