Coverage for hopwise/utils/enum_type.py: 97%
58 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-09-30 13:25 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-09-30 13:25 +0000
1# @Time : 2020/8/9
2# @Author : Yupeng Hou
3# @Email : houyupeng@ruc.edu.cn
5# UPDATE
6# @Time : 2025
7# @Author : Giacomo Medda
8# @Email : giacomo.medda@unica.it
10"""hopwise.utils.enum_type
11#######################
12"""
14from enum import Enum
17class ModelType(Enum):
18 """Type of models.
20 - ``GENERAL``: General Recommendation
21 - ``SEQUENTIAL``: Sequential Recommendation
22 - ``CONTEXT``: Context-aware Recommendation
23 - ``KNOWLEDGE``: Knowledge-based Recommendation
24 - ``PATH_LANGUAGE_MODELING``: Path Language Modeling Recommendation
25 """
27 GENERAL = 1
28 SEQUENTIAL = 2
29 CONTEXT = 3
30 KNOWLEDGE = 4
31 TRADITIONAL = 5
32 DECISIONTREE = 6
33 PATH_LANGUAGE_MODELING = 7
36class KGDataLoaderState(Enum):
37 """States for Knowledge-based DataLoader.
39 - ``RSKG``: Return both knowledge graph information and user-item interaction information.
40 - ``RS``: Only return the user-item interaction.
41 - ``KG``: Only return the triplets with negative examples in a knowledge graph.
42 """
44 RSKG = 1
45 RS = 2
46 KG = 3
49class KnowledgeEvaluationType(Enum):
50 """Type of evaluation task: Recommendation or Link Prediction
52 - ``REC``: Evaluate on Recommendation
53 - ``LP``: Evaluate on Link Prediction
54 """
56 REC = 1
57 LP = 2
59 def __str__(self):
60 _descriptions = {KnowledgeEvaluationType.REC: "recommendation", KnowledgeEvaluationType.LP: "link prediction"}
62 return _descriptions[self]
65class EvaluatorType(Enum):
66 """Type for evaluation metrics.
68 - ``RANKING``: Ranking-based metrics like NDCG, Recall, etc.
69 - ``VALUE``: Value-based metrics like AUC, etc.
70 """
72 RANKING = 1
73 VALUE = 2
76class InputType(Enum):
77 """Type of Models' input.
79 - ``POINTWISE``: Point-wise input, like ``uid, iid, label``.
80 - ``PAIRWISE``: Pair-wise input, like ``uid, pos_iid, neg_iid``.
81 - ``LISTWISE``: List-wise input, like ``uid, [iid1, iid2, ...]``.
82 - ``PATHWISE``: KG Path-wise input, like ``uid, pos_iid, eid1, eid2, next_pos_iid``.
83 - ``USERWISE``: User-wise input, like ``uid0, uid1, ...., uidn``.
84 """
86 POINTWISE = 1
87 PAIRWISE = 2
88 LISTWISE = 3
89 PATHWISE = 4
90 USERWISE = 5
93class FeatureType(Enum):
94 """Type of features.
96 - ``TOKEN``: Token features like user_id and item_id.
97 - ``FLOAT``: Float features like rating and timestamp.
98 - ``TOKEN_SEQ``: Token sequence features like review.
99 - ``FLOAT_SEQ``: Float sequence features like pretrained vector.
100 """
102 TOKEN = "token"
103 FLOAT = "float"
104 TOKEN_SEQ = "token_seq"
105 FLOAT_SEQ = "float_seq"
108class FeatureSource(Enum):
109 """Source of features.
111 - ``INTERACTION``: Features from ``.inter`` (other than ``user_id`` and ``item_id``).
112 - ``USER``: Features from ``.user`` (other than ``user_id``).
113 - ``ITEM``: Features from ``.item`` (other than ``item_id``).
114 - ``USER_ID``: ``user_id`` feature in ``inter_feat`` and ``user_feat``.
115 - ``ITEM_ID``: ``item_id`` feature in ``inter_feat`` and ``item_feat``.
116 - ``KG``: Features from ``.kg``.
117 - ``NET``: Features from ``.net``.
118 """
120 INTERACTION = "inter"
121 USER = "user"
122 ITEM = "item"
123 USER_ID = "user_id"
124 ITEM_ID = "item_id"
125 KG = "kg"
126 NET = "net"
129class PathLanguageModelingTokenType(Enum):
130 """Type of tokens in paths for Path Language Modeling.
132 - ``SPECIAL``: Special tokens, like start and end of a path.
133 - ``ENTITY``: Entity tokens.
134 - ``RELATION``: Relation tokens.
135 - ``USER``: User tokens.
136 - ``ITEM``: Item tokens.
137 """
139 SPECIAL = ("S", 0)
140 ENTITY = ("E", 1)
141 RELATION = ("R", 2)
142 USER = ("U", 3)
143 ITEM = ("I", 4)
145 def __init__(self, token, token_id):
146 self.token = token
147 self.token_id = token_id
149 def __str__(self):
150 return self.token
153class PathSamplingStrategy(Enum):
154 """Strategy for sampling paths from the knowledge graph.
156 - ``WEIGHTED_RW``: Weighted random walk with sampling-and-discarding approach.
157 - ``CONSTRAINED_RW``: Constrained random walk with type constraints.
158 - ``SIMPLE_UI``: Per-interaction coverage sampling; random walks anchored at each user-item interaction, ending at
159 another positive item, re-sampled until each interaction reaches its path quota (MAX_PATHS_PER_USER per pair).
161 """
163 WEIGHTED_RW = "weighted-rw"
164 CONSTRAINED_RW = "constrained-rw"
165 SIMPLE_UI = "simple-ui"
167 def __str__(self):
168 return self.value