Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nltk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
nltk
Commits
92200f1d
Commit
92200f1d
authored
Jan 17, 2013
by
David Doukhan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Distinction between weigthed and unweighted WindowDiff
Correction of bugs in the proposed version
parent
c3e40de3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
14 deletions
+12
-14
nltk/metrics/segmentation.py
+12
-14
No files found.
nltk/metrics/segmentation.py
View file @
92200f1d
...
@@ -48,23 +48,13 @@ except ImportError:
...
@@ -48,23 +48,13 @@ except ImportError:
from
nltk.compat
import
xrange
from
nltk.compat
import
xrange
def
windowdiff
(
seg1
,
seg2
,
k
,
boundary
=
"1"
):
def
windowdiff
(
seg1
,
seg2
,
k
,
boundary
=
"1"
,
weighted
=
True
):
"""
"""
Compute the windowdiff score for a pair of segmentations. A
Compute the windowdiff score for a pair of segmentations. A
segmentation is any sequence over a vocabulary of two items
segmentation is any sequence over a vocabulary of two items
(e.g. "0", "1"), where the specified boundary value is used to
(e.g. "0", "1"), where the specified boundary value is used to
mark the edge of a segmentation.
mark the edge of a segmentation.
>>> s1 = "00000010000000001000000"
>>> s2 = "00000001000000010000000"
>>> s3 = "00010000000000000001000"
>>> windowdiff(s1, s1, 3)
0
>>> windowdiff(s1, s2, 3)
4
>>> windowdiff(s2, s3, 3)
16
:param seg1: a segmentation
:param seg1: a segmentation
:type seg1: str or list
:type seg1: str or list
:param seg2: a segmentation
:param seg2: a segmentation
...
@@ -74,14 +64,22 @@ def windowdiff(seg1, seg2, k, boundary="1"):
...
@@ -74,14 +64,22 @@ def windowdiff(seg1, seg2, k, boundary="1"):
:param boundary: boundary value
:param boundary: boundary value
:type boundary: str or int or bool
:type boundary: str or int or bool
:rtype: int
:rtype: int
:param weighted: use the weighted variant of windowdiff
:rtype weighted: boolean
"""
"""
if
len
(
seg1
)
!=
len
(
seg2
):
if
len
(
seg1
)
!=
len
(
seg2
):
raise
ValueError
(
"Segmentations have unequal length"
)
raise
ValueError
(
"Segmentations have unequal length"
)
if
k
>
len
(
seg1
):
raise
ValueError
(
"Window width k should be smaller or equal than segmentation lengths"
)
wd
=
0
wd
=
0
for
i
in
range
(
len
(
seg1
)
-
k
):
for
i
in
range
(
len
(
seg1
)
-
k
+
1
):
wd
+=
abs
(
seg1
[
i
:
i
+
k
+
1
]
.
count
(
boundary
)
-
seg2
[
i
:
i
+
k
+
1
]
.
count
(
boundary
))
ndiff
=
abs
(
seg1
[
i
:
i
+
k
]
.
count
(
boundary
)
-
seg2
[
i
:
i
+
k
]
.
count
(
boundary
))
return
wd
if
weighted
:
wd
+=
ndiff
else
:
wd
+=
min
(
1
,
ndiff
)
return
wd
/
(
len
(
seg1
)
-
k
+
1.
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment