Skip to content

Commit

Permalink
add uri.is_term to include /x/ terms; use it in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Speer committed Dec 12, 2017
1 parent 5958dd3 commit d25ab9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions conceptnet5/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ def is_concept(uri):
return uri.startswith('/c/')


def is_term(uri):
return uri.startswith('/c/') or uri.startswith('/x/')


def is_absolute_url(uri):
# We have URLs pointing to Creative Commons licenses, starting with 'cc:',
# which for Linked Data purposes are absolute URLs because they'll be
Expand Down
11 changes: 6 additions & 5 deletions tests/small-build/test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pandas as pd
from nose.tools import ok_, eq_, assert_almost_equal

from conceptnet5.uri import is_term
from conceptnet5.vectors import get_vector
from conceptnet5.vectors.evaluation.compare import load_any_embeddings
from conceptnet5.vectors.query import VectorSpaceWrapper
Expand Down Expand Up @@ -37,21 +38,21 @@ def test_vector_space_wrapper(frame=None):
frame = load_any_embeddings(frame)
wrap = VectorSpaceWrapper(frame=frame)
wrap.load()
ok_(all(label.startswith('/c') for label in wrap.frame.index[1:]))
ok_(all(is_term(label) for label in wrap.frame.index[1:]))
ok_(wrap.frame.index.is_monotonic_increasing)

# Load a VSW from a filename
vector_filename = DATA + '/vectors/glove12-840B.h5'
wrap = VectorSpaceWrapper(vector_filename=vector_filename)
wrap.load()
ok_(all(label.startswith('/c') for label in wrap.frame.index[1:]))
ok_(all(is_term(label) for label in wrap.frame.index[1:]))
ok_(wrap.frame.index.is_monotonic_increasing)

# Load a VSW from a frame
frame = load_any_embeddings(DATA + '/vectors/glove12-840B.h5')
wrap = VectorSpaceWrapper(frame=frame)
wrap.load()
ok_(all(label.startswith('/c') for label in wrap.frame.index[1:]))
ok_(all(is_term(label) for label in wrap.frame.index[1:]))
ok_(wrap.frame.index.is_monotonic_increasing)


Expand All @@ -65,8 +66,8 @@ def test_standardize_row_labels(frame=None):
vec3 = vectors.loc['things']
standardized_vectors = standardize_row_labels(vectors)

# Check if all labels are concepts
ok_(all(label.startswith('/c') for label in standardized_vectors.index[1:]))
# Check if all labels are terms
ok_(all(is_term(label) for label in standardized_vectors.index[1:]))

# Check if all terms standardized to the same concept are merged
ok_(standardized_vectors.index.is_unique)
Expand Down

0 comments on commit d25ab9c

Please sign in to comment.