conceptnet_lite¶
Module contents¶
-
class
conceptnet_lite.
PartOfEdge
¶ Bases:
enum.Enum
An enumeration.
-
ANY
= 'any'¶
-
END
= 'end'¶
-
START
= 'start'¶
-
-
conceptnet_lite.
connect
(db_path='conceptnet.db', db_download_url='https://conceptnet-lite.fra1.cdn.digitaloceanspaces.com/conceptnet.db.zip', delete_compressed_db=True, dump_download_url='https://s3.amazonaws.com/conceptnet/downloads/2019/edges/conceptnet-assertions-5.7.0.csv.gz', load_dump_edge_count=34074917, delete_compressed_dump=True, delete_dump=True)¶ Connect to ConceptNet database.
This function connects to ConceptNet database. If it does not exists, there are two options: to download ready database or to download the compressed ConceptNet dump, extract it, and load it into database (pass db_download_url=None for this option).
- Parameters
db_path (
Union
[Path
,str
]) – Path to the database.db_download_url (
Optional
[str
]) – Link to compressed ConceptNet database. Pass None to build the db from dump.delete_compressed_db (
bool
) – Delete compressed database after extraction.dump_download_url (
str
) – Link to compressed ConceptNet dump.load_dump_edge_count (
int
) – Number of edges to load from the beginning of the dump file. Can be useful for testing.delete_compressed_dump (
bool
) – Delete compressed dump after unpacking.delete_dump (
bool
) – Delete dump after loading into database.
- Return type
None
-
conceptnet_lite.
edges
(part_of_edge, concepts, relation=None, same_language=False)¶ - Return type
ModelSelect
-
conceptnet_lite.
edges_between
(start_concepts, end_concepts, relation=None, two_way=False)¶ - Return type
ModelSelect
-
conceptnet_lite.
edges_for
(concepts, relation=None, same_language=False)¶ - Return type
ModelSelect
-
conceptnet_lite.
edges_from
(start_concepts, relation=None, same_language=False)¶ - Return type
ModelSelect
-
conceptnet_lite.
edges_to
(end_concepts, relation=None, same_language=False)¶ - Return type
ModelSelect
conceptnet_lite.db module¶
-
class
conceptnet_lite.db.
Concept
(*args, **kwargs)¶ Bases:
conceptnet_lite.db._BaseModel
Concept ORM class.
Concept
represents node in ConceptNet knowledge graph. It provides propertieslanguage
andtext
that are aliases for correspondingLabel.language
andLabel.text
fields.This abstraction is not present in the original ConceptNet. Class is introduced for the purposes of normalization.
-
DoesNotExist
¶ alias of
ConceptDoesNotExist
-
edges_in
¶
-
edges_out
¶
-
classmethod
get
(*query, **filters)¶
-
id
= <AutoField: Concept.id>¶
-
label
= <ForeignKeyField: Concept.label>¶
-
label_id
= <ForeignKeyField: Concept.label>¶
-
sense_label
= <TextField: Concept.sense_label>¶
-
property
text
¶ - Return type
str
-
property
uri
¶ - Return type
str
-
-
class
conceptnet_lite.db.
Edge
(*args, **kwargs)¶ Bases:
conceptnet_lite.db._BaseModel
Edge ORM class.
See: https://github.com/commonsense/conceptnet5/wiki/Edges.
Everything except relation, start, and end nodes is stored in
etc
field that is plaindict
.-
DoesNotExist
¶ alias of
EdgeDoesNotExist
-
end
= <ForeignKeyField: Edge.end>¶
-
end_id
= <ForeignKeyField: Edge.end>¶
-
etc
= <JSONField: Edge.etc>¶
-
classmethod
get
(*query, **filters)¶
-
id
= <AutoField: Edge.id>¶
-
relation
= <ForeignKeyField: Edge.relation>¶
-
relation_id
= <ForeignKeyField: Edge.relation>¶
-
start
= <ForeignKeyField: Edge.start>¶
-
start_id
= <ForeignKeyField: Edge.start>¶
-
property
uri
¶ - Return type
str
-
-
class
conceptnet_lite.db.
Label
(*args, **kwargs)¶ Bases:
conceptnet_lite.db._BaseModel
Label ORM class.
Label
can be seen as a part ofConcept
.Label
is basically a text on a certain language (most often, a word).This abstraction is not present in the original ConceptNet. Class is introduced for the purposes of normalization.
-
DoesNotExist
¶ alias of
LabelDoesNotExist
-
concepts
¶
-
classmethod
get
(*query, **filters)¶
-
id
= <AutoField: Label.id>¶
-
language
= <ForeignKeyField: Label.language>¶
-
language_id
= <ForeignKeyField: Label.language>¶
-
text
= <TextField: Label.text>¶
-
-
class
conceptnet_lite.db.
Language
(*args, **kwargs)¶ Bases:
conceptnet_lite.db._BaseModel
Language ORM class.
See: https://github.com/commonsense/conceptnet5/wiki/Languages.
-
DoesNotExist
¶ alias of
LanguageDoesNotExist
-
id
= <AutoField: Language.id>¶
-
labels
¶
-
name
= <TextField: Language.name>¶
-
-
class
conceptnet_lite.db.
Relation
(*args, **kwargs)¶ Bases:
conceptnet_lite.db._BaseModel
Relation ORM class.
See: https://github.com/commonsense/conceptnet5/wiki/Relations.
-
DoesNotExist
¶ alias of
RelationDoesNotExist
-
edges
¶
-
id
= <AutoField: Relation.id>¶
-
name
= <TextField: Relation.name>¶
-
property
uri
¶ - Return type
str
-
-
class
conceptnet_lite.db.
RelationName
¶ Bases:
object
Names of non-deprecated relations.
See: https://github.com/commonsense/conceptnet5/wiki/Relations.
-
ANTONYM
= 'antonym'¶
-
AT_LOCATION
= 'at_location'¶
-
CAPABLE_OF
= 'capable_of'¶
-
CAUSES
= 'causes'¶
-
CAUSES_DESIRE
= 'causes_desire'¶
-
CREATED_BY
= 'created_by'¶
-
DEFINED_AS
= 'defined_as'¶
-
DERIVED_FROM
= 'derived_from'¶
-
DESIRES
= 'desires'¶
-
DISTINCT_FROM
= 'distinct_from'¶
-
ETYMOLOGICALLY_DERIVED_FROM
= 'etymologically_derived_from'¶
-
ETYMOLOGICALLY_RELATED_TO
= 'etymologically_related_to'¶
-
EXTERNAL_URL
= 'external_url'¶
-
FORM_OF
= 'form_of'¶
-
HAS_A
= 'has_a'¶
-
HAS_CONTEXT
= 'has_context'¶
-
HAS_FIRST_SUBEVENT
= 'has_first_subevent'¶
-
HAS_LAST_SUBEVENT
= 'has_last_subevent'¶
-
HAS_PREREQUISITE
= 'has_prerequisite'¶
-
HAS_PROPERTY
= 'has_property'¶
-
HAS_SUBEVENT
= 'has_subevent'¶
-
IS_A
= 'is_a'¶
-
LOCATED_NEAR
= 'located_near'¶
-
MADE_OF
= 'made_of'¶
-
MANNER_OF
= 'manner_of'¶
-
MOTIVATED_BY_GOAL
= 'motivated_by_goal'¶
-
OBSTRUCTED_BY
= 'obstructed_by'¶
-
PART_OF
= 'part_of'¶
-
RECEIVES_ACTION
= 'receives_action'¶
-
RELATED_TO
= 'related_to'¶
-
SIMILAR_TO
= 'similar_to'¶
-
SYMBOL_OF
= 'symbol_of'¶
-
SYNONYM
= 'synonym'¶
-
USED_FOR
= 'used_for'¶
-
-
conceptnet_lite.db.
download_db
(url='https://conceptnet-lite.fra1.cdn.digitaloceanspaces.com/conceptnet.db.zip', db_path='conceptnet.db', delete_compressed_db=True)¶ Download compressed ConceptNet dump and extract it.
- Parameters
url (
str
) – Link to compressed ConceptNet database.db_path (
Union
[Path
,str
]) – Path to resulting database.delete_compressed_db (
bool
) – Delete compressed database after extraction.
- Return type
None
-
conceptnet_lite.db.
download_dump
(url='https://s3.amazonaws.com/conceptnet/downloads/2019/edges/conceptnet-assertions-5.7.0.csv.gz', out_dir_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/conceptnet-lite/checkouts/latest/docs/source'))¶ Download compressed ConceptNet dump.
- Parameters
url (
str
) – Link to the dump.out_dir_path (
Union
[Path
,str
]) – Dir where to store dump.
-
conceptnet_lite.db.
extract_compressed_dump
(compressed_dump_path, delete_compressed_dump=True)¶ Extract compressed ConceptNet dump.
- Parameters
compressed_dump_path (
Union
[Path
,str
]) – Path to compressed dump to extract.delete_compressed_dump (
bool
) – Delete compressed dump after extraction.
-
conceptnet_lite.db.
load_dump_to_db
(dump_path, db_path, edge_count=34074917, delete_dump=True)¶ Load dump to database.
- Parameters
dump_path (
Union
[Path
,str
]) – Path to dump to load.db_path (
Union
[Path
,str
]) – Path to resulting database.edge_count (
int
) – Number of edges to load from the beginning of the dump file. Can be useful for testing.delete_dump (
bool
) – Delete dump after loading into database.
-
conceptnet_lite.db.
prepare_db
(db_path, dump_download_url='https://s3.amazonaws.com/conceptnet/downloads/2019/edges/conceptnet-assertions-5.7.0.csv.gz', load_dump_edge_count=34074917, delete_compressed_dump=True, delete_dump=True)¶ Prepare ConceptNet database.
This function downloads the compressed ConceptNet dump, extracts it, and loads it into database. First two steps are optional, and are executed only if needed.
- Parameters
db_path (
Union
[Path
,str
]) – Path to the resulting database.dump_download_url (
str
) – Link to compressed ConceptNet dump.load_dump_edge_count (
int
) – Number of edges to load from the beginning of the dump file. Can be useful for testing.delete_compressed_dump (
bool
) – Delete compressed dump after extraction.delete_dump (
bool
) – Delete dump after loading into database.