Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
pymemri
Commits
76d95c46
Commit
76d95c46
authored
3 years ago
by
Eelco van der Wel
Browse files
Options
Download
Plain Diff
Merge branch 'schema-overwrites' into 'dev'
Improve overwriting central schema classes See merge request
!154
parents
59ed4f58
63648d1d
dev
add_oauth_v1
async_uploader_w_queue
aziz/gitlab
aziz/gitlab_slug
aziz/tweet_schema
comply_w_edgelists
del
delete-projects
disable_cert_verify
eelco/export-schema-json
eelco/refactor-plugins-module
gql-dataset
gql-endpoint
handle_trigger_registering
main
oauth1_simulator
prod
release-0.0.15
remove-nbdev
remove_default_dataset_filter
remove_qr_email
sz/add_delete_listener
sz/create_account_when_keys_are_present
test-pod-logs
trigger-schema
update_qr_message_
write_model_bugfix
v0.1.2
v0.1.0
v0.0.52
v0.0.51
v0.0.50
v0.0.48
v0.0.47
v0.0.46
v0.0.45
v0.0.44
v0.0.43
v0.0.42
v0.0.41
v0.0.40
v0.0.39
v0.0.38
v0.0.37
v0.0.36
v0.0.35
v0.0.34
v0.0.33
v0.0.32
v0.0.31
v0.0.30
v0.0.29
v0.0.28
v0.0.27
v0.0.26
v0.0.25
v0.0.24
v0.0.23
v0.0.22
v0.0.21
v0.0.20
v0.0.19
v0.0.18
v0.0.17
v0.0.16
v0.0.15c
v0.0.15b
v0.0.15a
v0.0.15-rc.1
2 merge requests
!154
Improve overwriting central schema classes
,
!145
Draft: Dev
Pipeline
#5522
passed with stages
in 3 minutes and 48 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
nbs/test_schema.ipynb
+17
-17
nbs/test_schema.ipynb
pymemri/data/_central_schema.py
+90
-14
pymemri/data/_central_schema.py
pymemri/data/schema.py
+1
-1
pymemri/data/schema.py
tools/generate_central_schema.sh
+5
-4
tools/generate_central_schema.sh
with
113 additions
and
36 deletions
+113
-36
nbs/test_schema.ipynb
+
17
-
17
View file @
76d95c46
...
...
@@ -5,16 +5,7 @@
"execution_count": null,
"id": "2d446f01",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
...
...
@@ -28,7 +19,7 @@
"outputs": [],
"source": [
"import inspect\n",
"from pymemri.data import central_schema\n",
"from pymemri.data import
_
central_schema\n",
"from pymemri.pod.client import PodClient"
]
},
...
...
@@ -42,7 +33,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"num schema classes: 4
2
\n"
"num schema classes: 4
4
\n"
]
}
],
...
...
@@ -50,8 +41,8 @@
"# Get all central schema classes\n",
"central_schema = {\n",
" k: v\n",
" for k, v in inspect.getmembers(central_schema)\n",
" if inspect.isclass(v) and v.__module__ == \"pymemri.data.central_schema\"\n",
" for k, v in inspect.getmembers(
_
central_schema)\n",
" if inspect.isclass(v) and v.__module__ == \"pymemri.data.
_
central_schema\"\n",
"}\n",
"print(\"num schema classes:\", len(central_schema))"
]
...
...
@@ -74,9 +65,18 @@
"execution_count": null,
"id": "8ea120f0",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"BULK: Writing 4/4 items/edges\n",
"Completed Bulk action, written 4 items/edges\n"
]
}
],
"source": [
"from pymemri.data.
central_
schema import EmailMessage, Country, Receipt, Account\n",
"from pymemri.data.schema import EmailMessage, Country, Receipt, Account\n",
"from datetime import datetime\n",
"\n",
"item_1 = EmailMessage(starred=True, content=\"This is a test\", dateSent=datetime.now())\n",
...
...
@@ -89,7 +89,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3
(ipykernel)
",
"language": "python",
"name": "python3"
}
...
...
%% Cell type:code id:2d446f01 tags:
```
python
%
load_ext
autoreload
%
autoreload
2
```
%% Output
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
%% Cell type:code id:870e5db2 tags:
```
python
import
inspect
from
pymemri.data
import
central_schema
from
pymemri.data
import
_
central_schema
from
pymemri.pod.client
import
PodClient
```
%% Cell type:code id:6d5242f4 tags:
```
python
# Get all central schema classes
central_schema
=
{
k
:
v
for
k
,
v
in
inspect
.
getmembers
(
central_schema
)
if
inspect
.
isclass
(
v
)
and
v
.
__module__
==
"pymemri.data.central_schema"
for
k
,
v
in
inspect
.
getmembers
(
_
central_schema
)
if
inspect
.
isclass
(
v
)
and
v
.
__module__
==
"pymemri.data.
_
central_schema"
}
print
(
"num schema classes:"
,
len
(
central_schema
))
```
%% Output
num schema classes: 4
2
num schema classes: 4
4
%% Cell type:code id:943e20bc tags:
```
python
client
=
PodClient
()
for
k
,
v
in
central_schema
.
items
():
assert
client
.
add_to_schema
(
v
),
f
"Could not add
{
k
}
to schema"
```
%% Cell type:code id:8ea120f0 tags:
```
python
from
pymemri.data.
central_
schema
import
EmailMessage
,
Country
,
Receipt
,
Account
from
pymemri.data.schema
import
EmailMessage
,
Country
,
Receipt
,
Account
from
datetime
import
datetime
item_1
=
EmailMessage
(
starred
=
True
,
content
=
"This is a test"
,
dateSent
=
datetime
.
now
())
item_2
=
Country
(
name
=
"Belgium"
)
item_3
=
Receipt
(
category
=
"clothing"
,
store
=
"clothing store"
,
totalCost
=
100000
)
item_4
=
Account
(
displayName
=
"1234"
,
identifier
=
"5678"
,
isMe
=
False
,
service
=
"whatsapp"
)
assert
client
.
bulk_action
(
create_items
=
[
item_1
,
item_2
,
item_3
,
item_4
])
```
%% Output
BULK: Writing 4/4 items/edges
Completed Bulk action, written 4 items/edges
...
...
This diff is collapsed.
Click to expand it.
pymemri/data/central_schema.py
→
pymemri/data/
_
central_schema.py
+
90
-
14
View file @
76d95c46
...
...
@@ -33,6 +33,7 @@ class Account(Item):
"ownCurrency"
,
"owner"
,
"trust"
,
"profilePicture"
,
]
def
__init__
(
...
...
@@ -57,6 +58,7 @@ class Account(Item):
ownCurrency
:
list
=
None
,
owner
:
list
=
None
,
trust
:
list
=
None
,
profilePicture
:
list
=
None
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
...
...
@@ -78,12 +80,15 @@ class Account(Item):
# Edges
self
.
changelog
:
list
=
changelog
if
changelog
is
not
None
else
[]
self
.
cryptoTransaction
:
list
=
cryptoTransaction
if
cryptoTransaction
is
not
None
else
[]
self
.
cryptoTransaction
:
list
=
(
cryptoTransaction
if
cryptoTransaction
is
not
None
else
[]
)
self
.
location
:
list
=
location
if
location
is
not
None
else
[]
self
.
network
:
list
=
network
if
network
is
not
None
else
[]
self
.
ownCurrency
:
list
=
ownCurrency
if
ownCurrency
is
not
None
else
[]
self
.
owner
:
list
=
owner
if
owner
is
not
None
else
[]
self
.
trust
:
list
=
trust
if
trust
is
not
None
else
[]
self
.
profilePicture
:
list
=
profilePicture
if
profilePicture
is
not
None
else
[]
class
AuditItem
(
Item
):
...
...
@@ -114,7 +119,9 @@ class CVUStoredDefinition(Item):
"itemType"
,
"name"
,
"querystr"
,
"renderer"
,
"selector"
,
"type"
,
]
edges
=
Item
.
edges
+
[]
...
...
@@ -125,7 +132,9 @@ class CVUStoredDefinition(Item):
itemType
:
str
=
None
,
name
:
str
=
None
,
querystr
:
str
=
None
,
renderer
:
str
=
None
,
selector
:
str
=
None
,
type
:
str
=
None
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
...
...
@@ -136,7 +145,9 @@ class CVUStoredDefinition(Item):
self
.
itemType
:
Optional
[
str
]
=
itemType
self
.
name
:
Optional
[
str
]
=
name
self
.
querystr
:
Optional
[
str
]
=
querystr
self
.
renderer
:
Optional
[
str
]
=
renderer
self
.
selector
:
Optional
[
str
]
=
selector
self
.
type
:
Optional
[
str
]
=
type
class
CreativeWork
(
Item
):
...
...
@@ -182,9 +193,13 @@ class CreativeWork(Item):
self
.
transcript
:
Optional
[
str
]
=
transcript
# Edges
self
.
contentLocation
:
list
=
contentLocation
if
contentLocation
is
not
None
else
[]
self
.
contentLocation
:
list
=
(
contentLocation
if
contentLocation
is
not
None
else
[]
)
self
.
file
:
list
=
file
if
file
is
not
None
else
[]
self
.
locationCreated
:
list
=
locationCreated
if
locationCreated
is
not
None
else
[]
self
.
locationCreated
:
list
=
(
locationCreated
if
locationCreated
is
not
None
else
[]
)
self
.
writtenBy
:
list
=
writtenBy
if
writtenBy
is
not
None
else
[]
...
...
@@ -210,7 +225,9 @@ class CryptoCurrency(Item):
self
.
topic
:
Optional
[
str
]
=
topic
# Edges
self
.
currencySetting
:
list
=
currencySetting
if
currencySetting
is
not
None
else
[]
self
.
currencySetting
:
list
=
(
currencySetting
if
currencySetting
is
not
None
else
[]
)
self
.
picture
:
list
=
picture
if
picture
is
not
None
else
[]
...
...
@@ -308,6 +325,19 @@ class CurrencySetting(Item):
self
.
wallet
:
list
=
wallet
if
wallet
is
not
None
else
[]
class
Dataset
(
Item
):
description
=
"""A Dataset of items."""
properties
=
Item
.
properties
+
[
"name"
,
"querystr"
]
edges
=
Item
.
edges
+
[]
def
__init__
(
self
,
name
:
str
=
None
,
querystr
:
str
=
None
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
# Properties
self
.
name
:
Optional
[
str
]
=
name
self
.
querystr
:
Optional
[
str
]
=
querystr
class
Diet
(
Item
):
description
=
"""A strategy of regulating the intake of food to achieve or maintain a specific health-related goal."""
properties
=
Item
.
properties
+
[
...
...
@@ -357,15 +387,19 @@ class Diet(Item):
self
.
transcript
:
Optional
[
str
]
=
transcript
# Edges
self
.
contentLocation
:
list
=
contentLocation
if
contentLocation
is
not
None
else
[]
self
.
contentLocation
:
list
=
(
contentLocation
if
contentLocation
is
not
None
else
[]
)
self
.
file
:
list
=
file
if
file
is
not
None
else
[]
self
.
locationCreated
:
list
=
locationCreated
if
locationCreated
is
not
None
else
[]
self
.
locationCreated
:
list
=
(
locationCreated
if
locationCreated
is
not
None
else
[]
)
self
.
writtenBy
:
list
=
writtenBy
if
writtenBy
is
not
None
else
[]
class
File
(
Item
):
description
=
"""Any file that can be stored on disk."""
properties
=
Item
.
properties
+
[
"filename"
,
"keystr"
,
"nonce"
,
"sha256"
]
properties
=
Item
.
properties
+
[
"filename"
,
"keystr"
,
"nonce"
,
"sha256"
,
"starred"
]
edges
=
Item
.
edges
+
[]
def
__init__
(
...
...
@@ -374,6 +408,7 @@ class File(Item):
keystr
:
str
=
None
,
nonce
:
str
=
None
,
sha256
:
str
=
None
,
starred
:
bool
=
None
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
...
...
@@ -383,6 +418,7 @@ class File(Item):
self
.
keystr
:
Optional
[
str
]
=
keystr
self
.
nonce
:
Optional
[
str
]
=
nonce
self
.
sha256
:
Optional
[
str
]
=
sha256
self
.
starred
:
Optional
[
bool
]
=
starred
class
Integrator
(
Item
):
...
...
@@ -473,6 +509,48 @@ class LabelAnnotation(Item):
self
.
annotatedItem
:
list
=
annotatedItem
if
annotatedItem
is
not
None
else
[]
class
LabelingDataType
(
Item
):
description
=
"""A labelling data type definition."""
properties
=
Item
.
properties
+
[
"name"
,
"icon"
]
edges
=
Item
.
edges
+
[
"dataset"
]
def
__init__
(
self
,
name
:
str
=
None
,
icon
:
str
=
None
,
dataset
:
list
=
None
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
# Properties
self
.
name
:
Optional
[
str
]
=
name
self
.
icon
:
Optional
[
str
]
=
icon
# Edges
self
.
dataset
:
list
=
dataset
if
dataset
is
not
None
else
[]
class
LabelingTask
(
Item
):
description
=
"""A labelling task definition."""
properties
=
Item
.
properties
+
[
"name"
]
edges
=
Item
.
edges
+
[
"labelOption"
,
"dataset"
,
"view"
]
def
__init__
(
self
,
name
:
str
=
None
,
labelOption
:
list
=
None
,
dataset
:
list
=
None
,
view
:
list
=
None
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
# Properties
self
.
name
:
Optional
[
str
]
=
name
# Edges
self
.
labelOption
:
list
=
labelOption
if
labelOption
is
not
None
else
[]
self
.
dataset
:
list
=
dataset
if
dataset
is
not
None
else
[]
self
.
view
:
list
=
view
if
view
is
not
None
else
[]
class
Location
(
Item
):
description
=
"""The location of something."""
properties
=
Item
.
properties
+
[
"latitude"
,
"longitude"
]
...
...
@@ -701,7 +779,9 @@ class Person(Item):
self
.
hasPhoneNumber
:
list
=
hasPhoneNumber
if
hasPhoneNumber
is
not
None
else
[]
self
.
label
:
list
=
label
if
label
is
not
None
else
[]
self
.
me
:
list
=
me
if
me
is
not
None
else
[]
self
.
medicalCondition
:
list
=
medicalCondition
if
medicalCondition
is
not
None
else
[]
self
.
medicalCondition
:
list
=
(
medicalCondition
if
medicalCondition
is
not
None
else
[]
)
self
.
mergedFrom
:
list
=
mergedFrom
if
mergedFrom
is
not
None
else
[]
self
.
profilePicture
:
list
=
profilePicture
if
profilePicture
is
not
None
else
[]
self
.
relationship
:
list
=
relationship
if
relationship
is
not
None
else
[]
...
...
@@ -1150,29 +1230,25 @@ class Note(WrittenWork):
class
EmailMessage
(
Message
):
description
=
"""A single email message."""
properties
=
Message
.
properties
+
[
"starred"
,
"read"
]
edges
=
Message
.
edges
+
[
"bcc"
,
"cc"
,
"message"
,
"replyTo"
,
"inbox"
]
properties
=
Message
.
properties
+
[
"starred"
]
edges
=
Message
.
edges
+
[
"bcc"
,
"cc"
,
"message"
,
"replyTo"
]
def
__init__
(
self
,
starred
:
bool
=
None
,
read
:
bool
=
None
,
bcc
:
list
=
None
,
cc
:
list
=
None
,
message
:
list
=
None
,
replyTo
:
list
=
None
,
inbox
:
list
=
None
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
# Properties
self
.
starred
:
Optional
[
bool
]
=
starred
self
.
read
:
Optional
[
bool
]
=
read
# Edges
self
.
bcc
:
list
=
bcc
if
bcc
is
not
None
else
[]
self
.
cc
:
list
=
cc
if
cc
is
not
None
else
[]
self
.
message
:
list
=
message
if
message
is
not
None
else
[]
self
.
replyTo
:
list
=
replyTo
if
replyTo
is
not
None
else
[]
self
.
inbox
:
list
=
inbox
if
inbox
is
not
None
else
[]
This diff is collapsed.
Click to expand it.
pymemri/data/schema.py
+
1
-
1
View file @
76d95c46
import
random
,
string
from
.itembase
import
ItemBase
,
Edge
,
Item
from
.central_schema
import
*
from
.
_
central_schema
import
*
from
.photo
import
Photo
...
...
This diff is collapsed.
Click to expand it.
tools/generate_central_schema.sh
+
5
-
4
View file @
76d95c46
#!/bin/bash
SCHEMA_REPO
=
"https://gitlab.memri.io/memri/schema.git"
BRANCH
=
"
schema-cleanup
"
BRANCH
=
"
dev
"
OUT_DIR
=
"
$(
pwd
)
/pymemri/data"
FILENAME
=
"central_schema.py"
FILENAME
=
"
_
central_schema.py"
if
[
!
-d
$OUT_DIR
]
;
then
echo
"Run script from pymemri root folder."
...
...
@@ -14,11 +14,12 @@ mkdir -p /tmp/pymemri && cd /tmp/pymemri
{
cd
schema
git checkout
$BRANCH
git pull
}
&> /dev/null
||
{
}
||
{
git clone
-b
$BRANCH
$SCHEMA_REPO
cd
schema
}
&> /dev/null
}
python tools/export_pymemri.py
-o
$OUT_DIR
/
$FILENAME
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Explore
Projects
Groups
Snippets