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
c09ae1a1
Commit
c09ae1a1
authored
Sep 05, 2012
by
Alex Rudnick
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #291 from pflaquerre/plug-dependencygraph-fd-leak
Plug DependencyGraph file descriptor leak
parents
d45d76f5
3613d831
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
8 deletions
+9
-8
nltk/parse/dependencygraph.py
+9
-8
No files found.
nltk/parse/dependencygraph.py
View file @
c09ae1a1
...
@@ -15,6 +15,9 @@ The input is assumed to be in Malt-TAB format
...
@@ -15,6 +15,9 @@ The input is assumed to be in Malt-TAB format
Currently only reads the first tree in a file.
Currently only reads the first tree in a file.
"""
"""
# python2.5 compatibility
from
__future__
import
with_statement
from
nltk.tree
import
Tree
from
nltk.tree
import
Tree
from
pprint
import
pformat
from
pprint
import
pformat
import
re
import
re
...
@@ -118,7 +121,8 @@ class DependencyGraph(object):
...
@@ -118,7 +121,8 @@ class DependencyGraph(object):
"""
"""
:param file: a file in Malt-TAB format
:param file: a file in Malt-TAB format
"""
"""
return
DependencyGraph
(
open
(
file
)
.
read
())
with
open
(
file
)
as
f
:
return
DependencyGraph
(
f
.
read
())
@staticmethod
@staticmethod
def
_normalize
(
line
):
def
_normalize
(
line
):
...
@@ -239,7 +243,6 @@ class DependencyGraph(object):
...
@@ -239,7 +243,6 @@ class DependencyGraph(object):
for
dep
in
node
[
'deps'
]:
for
dep
in
node
[
'deps'
]:
key
=
tuple
([
node
[
'address'
],
dep
])
#'%d -> %d' % (node['address'], dep)
key
=
tuple
([
node
[
'address'
],
dep
])
#'%d -> %d' % (node['address'], dep)
distances
[
key
]
=
1
distances
[
key
]
=
1
window
=
0
for
n
in
range
(
len
(
self
.
nodelist
)):
for
n
in
range
(
len
(
self
.
nodelist
)):
new_entries
=
{}
new_entries
=
{}
for
pair1
in
distances
:
for
pair1
in
distances
:
...
@@ -343,12 +346,10 @@ Nov. NNP 9 VMOD
...
@@ -343,12 +346,10 @@ Nov. NNP 9 VMOD
print
tree
.
pprint
()
print
tree
.
pprint
()
if
nx
:
if
nx
:
#currently doesn't work
#currently doesn't work
try
:
import
networkx
as
NX
import
networkx
as
NX
import
pylab
as
P
import
pylab
as
P
except
ImportError
:
g
=
dg
.
nx_graph
()
raise
g
=
dg
.
nx_graph
()
g
.
info
()
g
.
info
()
pos
=
NX
.
spring_layout
(
g
,
dim
=
1
)
pos
=
NX
.
spring_layout
(
g
,
dim
=
1
)
NX
.
draw_networkx_nodes
(
g
,
pos
,
node_size
=
50
)
NX
.
draw_networkx_nodes
(
g
,
pos
,
node_size
=
50
)
...
...
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