-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import rltk | ||
|
||
|
||
class Record1(rltk.Record): | ||
remove_raw_object = True | ||
|
||
@rltk.cached_property | ||
def id(self): | ||
print('--> compute id:', self.raw_object['doc_id']) | ||
return self.raw_object['doc_id'] | ||
|
||
@rltk.cached_property | ||
def value(self): | ||
print('--> compute value:', self.raw_object['doc_value']) | ||
return self.raw_object['doc_value'] | ||
|
||
@property | ||
def id_and_value(self): | ||
print('--> compute id_and_value') | ||
return self.id + '-' + self.value | ||
|
||
|
||
arr = [ | ||
{'doc_id': '1', 'doc_value': 'a'}, | ||
{'doc_id': '2', 'doc_value': 'b'}, | ||
{'doc_id': '3', 'doc_value': 'c'} | ||
] | ||
ds1 = rltk.Dataset(reader=rltk.ArrayReader(arr), record_class=Record1) | ||
for r1 in ds1: | ||
print('------------') | ||
print('id:', r1.id) | ||
print('value:', r1.value) | ||
print('id_and_value:', r1.id_and_value) | ||
print('cache in dict:', r1.__dict__) |