Python OSDK¶
This page provides generic documentation for Python OSDK based on an Example Restaurant object. You can generate documentation specific to your Ontology in Developer Console.
| Property | API Name | Type |
|---|---|---|
| Restaurant Id (Primary key) | restaurantId | String |
| Restaurant Name (Title) | restaurantName | String |
| Address | address | String |
| E Mail | String | |
| Number Of Reviews | numberOfReviews | Integer |
| Phone Number | phoneNumber | String |
| Review Summary | reviewSummary | String |
Load single restaurant¶
Parameters:
- primaryKey
string: The primary key of the Example Restaurant you want to fetch
Example query:
result = client.ontology.objects.ExampleRestaurant.get("primaryKey")
Example API response:
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"eMail": "E Mail",
"restaurantId": "Restaurant Id",
"address": "Address",
"reviewSummary": "Review Summary",
"phoneNumber": "Phone Number",
"numberOfReviews": 123,
"restaurantName": "Restaurant Name"
}
Load pages of example restaurants¶
Load a list of objects of a requested page size, after a given page token if present.
Note that this endpoint leverages the underlying object syncing technology used for the object type. If Example Restaurant is backed by Object Storage V2, there is no request limit. If it is backed by Phonograph, there is a limit of 10,000 results – when more than 10,000 Example Restaurants have been requested, a ObjectsExceededLimit error will be thrown.
Parameters:
- pageSize
integer(optional): The size of the page to request up to a maximum of 10,000. If not provided, will load up to 10,000 Example Restaurants. ThepageSizeof the initial page is used for subsequent pages. - pageToken
string(optional): If provided, will request a page with size less than or equal to thepageSizeof the first requested page.
Example query:
result = client.ontology.objects.ExampleRestaurant.page(page_size=30, page_token=None)
page_token = result.next_page_token
data = result.data
Example API response:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"eMail": "E Mail",
"restaurantId": "Restaurant Id",
"address": "Address",
"reviewSummary": "Review Summary",
"phoneNumber": "Phone Number",
"numberOfReviews": 123,
"restaurantName": "Restaurant Name"
}
// ... Rest of page
]
}
Load all example restaurants¶
Loads all Example Restaurants. Depending on the language, results could be a list with all rows or an iterator to loop through all rows.
Note that this endpoint leverages the underlying object syncing technology used for the object type. If Example Restaurant is backed by Object Storage V2, there is no request limit. If it is backed by Phonograph, there is a limit of 10,000 results – when more than 10,000 Example Restaurants have been requested, a ObjectsExceededLimit error will be thrown.
Example query:
objects_iterator = client.ontology.objects.ExampleRestaurant.iterate()
objects = list(objects_iterator)
Example API response:
{
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"eMail": "E Mail",
"restaurantId": "Restaurant Id",
"address": "Address",
"reviewSummary": "Review Summary",
"phoneNumber": "Phone Number",
"numberOfReviews": 123,
"restaurantName": "Restaurant Name"
}
// ... Rest of data
]
}
Load ordered results¶
Load an ordered list of Example Restaurants by specifying a sort direction for specific properties. When calling via APIs, sorting criteria are specified via the fields array. When calling via SDKs, you can chain multiple orderBy calls together. The sort order for strings is case-sensitive, meaning numbers will come before uppercase letters, which will come before lowercase letters. For example, Cat will come before bat.
Parameters:
- field
string: The property you want to sort by. With the SDK, this is provided for you via asortByinterface. - direction
asc|desc: The direction you want to sort in, either ascending or descending. With the SDK, this is provided via theasc()anddesc()functions on thesortByinterface.
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
client.ontology.objects.ExampleRestaurant.where(~ExampleRestaurant.object_type.restaurant_name.is_null()).order_by(ExampleRestaurant.object_type.restaurant_name.asc()).iterate()
Example API response:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Object A",
"restaurantName": "A"
// ...Rest of properties
},
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Object B",
"restaurantName": "B"
// ...Rest of properties
}
// ...Rest of page
]
}
Filtering¶
The types of filtering you can perform depend on the types of the properties on a given object type. These filters can also be combined together via Boolean expressions to construct more complex filters.
Note that this endpoint leverages the underlying object syncing technology used for the object type. If Example Restaurant is backed by Object Storage V2, there is no request limit. If it is backed by Object Storage V1 (Phonograph), there is a limit of 10,000 results – when more than 10,000 Example Restaurants have been requested, a ObjectsExceededLimit error will be thrown.
Parameters:
- where
SearchQuery(optional): Filter on a particular property. The possible operations depend on the type of the property. - orderBy
OrderByQuery(optional): Order the results based on a particular property. If using the SDK, you can chain the.wherecall with anorderBycall to achieve the same result. - pageSize
integer(optional): The size of the page to request up to a maximum of 10,000. If not provided, will load up to 10,000 Example Restaurants. ThepageSizeof the initial page is used for subsequent pages. If using the SDK, chain the.wherecall with the.pagemethod. - pageToken
string(optional): If provided, will request a page with size less than or equal to thepageSizeof the first requested page. If using the SDK, chain the.wherecall with the.pagemethod.
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
page = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.is_null()).iterate()
Example API response:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": null
// ... Rest of properties
}
// ... Rest of page
]
}
Types of search filters (SearchQuery)¶
Starts with¶
Only applies to String properties. Searches for Example Restaurants where restaurantName starts with the given string (case insensitive).
Parameters:
- field
string: Name of the property to use (for example, restaurantName). - value
string: Value to use for prefix matching against Restaurant Name. For example, "foo" will match "foobar" but not "barfoo".
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.starts_with(['foo']))
Example API response:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": "foobar"
// ... Rest of properties
}
]
}
Contains any terms¶
Only applies to String properties. Returns Example Restaurants where restaurantName contains any of the whitespace separated words (case insensitive) in any order in the provided value.
Parameters:
- field
string: Name of the property to use (for example, restaurantName). - value
string: White-space separated set of words to match on. For example, "foo bar" will match "bar baz" but not "baz qux". - fuzzy
boolean: Allows approximate matching in search queries.
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.contains_any_term(['foo bar']))
Example API response:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": "foo bar baz"
// ... Rest of properties
},
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000001",
"restaurantName": "bar baz"
// ... Rest of properties
}
]
}
Contains all terms¶
Only applies to String properties. Returns Example Restaurants where restaurantName contains all the whitespace separated words (case insensitive) in any order in the provided value.
Parameters:
- field
string: Name of the property to use (for example, restaurantName). - value
string: White-space separated set of words to match on. For example, "foo bar" will match "hello foo baz bar" but not "foo qux". - fuzzy
boolean: Allows approximate matching in search queries.
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.contains_all_terms(['foo bar']))
Example API response:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": "hello foo baz bar"
// ... Rest of properties
}
]
}
Contains all terms in order¶
Only applies to String properties. Returns Example Restaurants where restaurantName contains all the terms in the order provided (case insensitive), but they do have to be adjacent to each other.
Parameters:
- field
string: Name of the property to use (for example, restaurantName). - value
string: White-space separated set of words to match on. For example, "foo bar" will match "hello foo bar baz" but not "bar foo qux". - fuzzy
boolean: Allows approximate matching in search queries
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.contains_all_terms_in_order(['foo bar']))
Example API response:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": "foo bar baz"
// ... Rest of properties
}
]
}
Range comparison¶
Only applies to Numeric, String and DateTime properties. Returns Example Restaurants where ExampleRestaurant.object_type.restaurantName is less than a value.
Parameters:
- field
string: Name of the property to use (for example, restaurantName). - value
string: Value to compare Restaurant Name again
Comparison types:
- Less than
< - Greater than
> - Less than or equal to
<= - Greater than or equal to
>=
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name < "Restaurant Name")
Equal to¶
Only applies to Boolean, DateTime, Numeric, and String properties. Searches for Example Restaurants where restaurantName equals the given value.
Parameters:
- field
string: Name of the property to use (for example, restaurantName). - value
string: Value to do an equality check with Restaurant Name.
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name == "Restaurant Name")
Example API response:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": "Restaurant Name"
// ... Rest of properties
}
]
}
Null check¶
Only applies to Array, Boolean, DateTime, Numeric, and String properties. Searches for Example Restaurants based on whether a value for restaurantName exists or not.
Parameters:
- field
string: Name of the property to use (for example, restaurantName). - value
boolean: Whether Restaurant Name exists. Note for the TypeScript SDK, you will need to use a not filter for checking that fields are non-null.
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.is_null())
Not filter¶
Returns Example Restaurants where the query is not satisfied. This can be further combined with other boolean filter operations.
Parameters:
- value
SearchQuery: The search query to invert.
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(~ExampleRestaurant.object_type.restaurantId.is_null())
And filter¶
Returns Example Restaurants where all queries are satisfied. This can be further combined with other boolean filter operations.
Parameters:
- value
SearchQuery[]: The set of search queries toandtogether.
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(~ExampleRestaurant.object_type.restaurantId.is_null() & (ExampleRestaurant.restaurantId == '<primaryKey>'))
Or filter¶
Returns Example Restaurants where any of the specified queries are satisfied. This can be further combined with other Boolean filter operations.
Parameters:
- value
SearchQuery[]: The set of search queries toortogether.
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurantId.is_null() | (ExampleRestaurant.object_type.restaurantId == '<primaryKey>'))
Aggregations¶
Perform aggregations on Example Restaurants.
Parameters:
- aggregation
Aggregation[](optional): Set of aggregation functions to perform. With the SDK, aggregation computations can be chained together with further searches using.where. - groupBy
GroupBy[](optional): A set of groupings to create for aggregation results - where
SearchQuery(optional): Filter on a particular property. The possible operations depend on the type of the property.
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
numExampleRestaurant = client.ontology.objects.ExampleRestaurant
.where(~ExampleRestaurant.object_type.restaurant_name).is_null())
.group_by(ExampleRestaurant.object_type.restaurant_name).exact())
.count()
.compute()
Example API response:
{
excludedItems: 0,
data: [{
group: {
"restaurantName": "Restaurant Name"
},
metrics: [
{
name: "count",
value: 100
}
]
}]
}
Types of aggregations (Aggregation)¶
Approximate distinct¶
Computes an approximate number of distinct values for restaurantName.
Parameters:
- field
string: Name of the property to use (for example, restaurantName). - name
string(optional): Alias for the computed count. By default, this is "distinctCount"
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
numExampleRestaurant = client.ontology.objects.ExampleRestaurant
.approximate_distinct(ExampleRestaurant.object_type.restaurant_name)
.compute()
# This is equivalent to the above, but uses metric_name as the name instead of the default "distinctCount"
numExampleRestaurant = client.ontology.objects.ExampleRestaurant
.aggregate(
{"metric_name": ExampleRestaurant.object_type.restaurant_name.approximate_distinct()}
)
.compute()
Example API response:
{
excludedItems: 0,
data: [{
group: {},
metrics: [
{
name: "distinctCount",
value: 100
}
]
}]
}
Count¶
Computes the total count of Example Restaurants.
Parameters:
- name
string(optional): Alias for the computed count. By default, this iscount.
Example query:
numExampleRestaurant = client.ontology.objects.ExampleRestaurant
.count()
.compute()
Example API response:
{
excludedItems: 0,
data: [{
group: {},
metrics: [
{
name: "count",
value: 100
}
]
}]
}
Numeric aggregations¶
Only applies to numeric properties. Calculate the maximum, minimum, sum, or average of a numeric property for Example Restaurants.
Parameters:
- field string: Name of the property to use (for example, numberOfReviews).
- name string (optional): An alias for the computed value. By default, this is "avg"
Aggregation types:
- Average:
avg() - Maximum:
max() - Minimum:
min() - Sum:
sum()
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
avgExampleRestaurant = client.ontology.objects.ExampleRestaurant
.avg(ExampleRestaurant.object_type.number_of_reviews)
.compute()
# This is equivalent to the above, but uses metric_name as the name instead of the default "avg"
avgExampleRestaurant = client.ontology.objects.ExampleRestaurant
.aggregate(
{"metric_name": ExampleRestaurant.object_type.number_of_reviews.avg()}
)
.compute()
Example API response:
{
excludedItems: 0,
data: [{
group: {},
metrics: [
{
name: "avg",
value: 100
}
]
}]
}
Types of group bys (GroupBy)¶
Exact grouping¶
Groups Example Restaurants by exact values of restaurantName.
Parameters:
- field
string: Name of the property to use (for example, restaurantName). - maxGroupCount
integer(optional): Maximum number of groupings of restaurantName to create.
Example query:
from ontology_sdk.ontology.objects import ExampleRestaurant
numExampleRestaurant = client.ontology.objects.ExampleRestaurant
.group_by(ExampleRestaurant.object_type.restaurant_name.exact())
.count()
.compute()
Example API response:
{
excludedItems: 0,
data: [{
group: {
"restaurantName": "Restaurant Name"
},
metrics: [
{
name: "count",
value: 100
}
]
}]
}
中文翻译¶
Python OSDK¶
本页面提供了基于示例餐厅(Example Restaurant)对象的Python OSDK通用文档。您可以在开发者控制台(Developer Console)中生成特定于您本体论(Ontology)的文档。
| 属性 | API名称 | 类型 |
|---|---|---|
| 餐厅ID(主键) | restaurantId | String |
| 餐厅名称(标题) | restaurantName | String |
| 地址 | address | String |
| 电子邮件 | String | |
| 评论数量 | numberOfReviews | Integer |
| 电话号码 | phoneNumber | String |
| 评论摘要 | reviewSummary | String |
加载单个餐厅¶
参数:
- primaryKey
string:要获取的示例餐厅(Example Restaurant)的主键
示例查询:
result = client.ontology.objects.ExampleRestaurant.get("primaryKey")
示例API响应:
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"eMail": "E Mail",
"restaurantId": "Restaurant Id",
"address": "Address",
"reviewSummary": "Review Summary",
"phoneNumber": "Phone Number",
"numberOfReviews": 123,
"restaurantName": "Restaurant Name"
}
加载示例餐厅的分页数据¶
加载指定页面大小的对象列表,如果提供了分页令牌(page token),则从该令牌之后开始加载。
请注意,此端点利用了对象类型所使用的底层对象同步技术。如果示例餐厅(Example Restaurant)由Object Storage V2支持,则没有请求限制。如果由Phonograph支持,则结果限制为10,000条——当请求超过10,000个示例餐厅时,将抛出ObjectsExceededLimit错误。
参数:
- pageSize
integer(可选):请求的页面大小,最大为10,000。如果未提供,将加载最多10,000个示例餐厅。初始页面的pageSize将用于后续页面。 - pageToken
string(可选):如果提供,将请求一个大小小于或等于首次请求页面pageSize的页面。
示例查询:
result = client.ontology.objects.ExampleRestaurant.page(page_size=30, page_token=None)
page_token = result.next_page_token
data = result.data
示例API响应:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"eMail": "E Mail",
"restaurantId": "Restaurant Id",
"address": "Address",
"reviewSummary": "Review Summary",
"phoneNumber": "Phone Number",
"numberOfReviews": 123,
"restaurantName": "Restaurant Name"
}
// ... 页面其余部分
]
}
加载所有示例餐厅¶
加载所有示例餐厅(Example Restaurant)。根据语言不同,结果可以是包含所有行的列表,也可以是用于遍历所有行的迭代器。
请注意,此端点利用了对象类型所使用的底层对象同步技术。如果示例餐厅由Object Storage V2支持,则没有请求限制。如果由Phonograph支持,则结果限制为10,000条——当请求超过10,000个示例餐厅时,将抛出ObjectsExceededLimit错误。
示例查询:
objects_iterator = client.ontology.objects.ExampleRestaurant.iterate()
objects = list(objects_iterator)
示例API响应:
{
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"eMail": "E Mail",
"restaurantId": "Restaurant Id",
"address": "Address",
"reviewSummary": "Review Summary",
"phoneNumber": "Phone Number",
"numberOfReviews": 123,
"restaurantName": "Restaurant Name"
}
// ... 数据其余部分
]
}
加载排序结果¶
通过为特定属性指定排序方向,加载排序后的示例餐厅(Example Restaurant)列表。通过API调用时,排序条件通过fields数组指定。通过SDK调用时,可以链式调用多个orderBy。字符串的排序顺序区分大小写,这意味着数字会排在大写字母之前,大写字母会排在小写字母之前。例如,Cat会排在bat之前。
参数:
- field
string:要排序的属性。使用SDK时,通过sortBy接口为您提供。 - direction
asc|desc:排序方向,升序或降序。使用SDK时,通过sortBy接口上的asc()和desc()函数提供。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
client.ontology.objects.ExampleRestaurant.where(~ExampleRestaurant.object_type.restaurant_name.is_null()).order_by(ExampleRestaurant.object_type.restaurant_name.asc()).iterate()
示例API响应:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Object A",
"restaurantName": "A"
// ...其余属性
},
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Object B",
"restaurantName": "B"
// ...其余属性
}
// ...页面其余部分
]
}
过滤¶
可执行的过滤类型取决于给定对象类型上属性的类型。这些过滤器还可以通过布尔表达式组合在一起,构建更复杂的过滤器。
请注意,此端点利用了对象类型所使用的底层对象同步技术。如果示例餐厅(Example Restaurant)由Object Storage V2支持,则没有请求限制。如果由Object Storage V1 (Phonograph)支持,则结果限制为10,000条——当请求超过10,000个示例餐厅时,将抛出ObjectsExceededLimit错误。
参数:
- where
SearchQuery(可选):对特定属性进行过滤。可能的操作取决于属性的类型。 - orderBy
OrderByQuery(可选):基于特定属性对结果进行排序。如果使用SDK,可以将.where调用与orderBy调用链式组合以达到相同效果。 - pageSize
integer(可选):请求的页面大小,最大为10,000。如果未提供,将加载最多10,000个示例餐厅。初始页面的pageSize将用于后续页面。如果使用SDK,将.where调用与.page方法链式组合。 - pageToken
string(可选):如果提供,将请求一个大小小于或等于首次请求页面pageSize的页面。如果使用SDK,将.where调用与.page方法链式组合。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
page = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.is_null()).iterate()
示例API响应:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": null
// ... 其余属性
}
// ... 页面其余部分
]
}
搜索过滤器类型 (SearchQuery)¶
开头匹配 (Starts with)¶
仅适用于字符串(String)属性。搜索restaurantName以给定字符串开头的示例餐厅(Example Restaurant)(不区分大小写)。
参数:
- field
string:要使用的属性名称(例如,restaurantName)。 - value
string:用于与餐厅名称进行前缀匹配的值。例如,"foo"将匹配"foobar",但不匹配"barfoo"。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.starts_with(['foo']))
示例API响应:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": "foobar"
// ... 其余属性
}
]
}
包含任意词 (Contains any terms)¶
仅适用于字符串(String)属性。返回restaurantName包含提供的值中任意空格分隔词(不区分大小写,顺序不限)的示例餐厅(Example Restaurant)。
参数:
- field
string:要使用的属性名称(例如,restaurantName)。 - value
string:要匹配的空格分隔词集。例如,"foo bar"将匹配"bar baz",但不匹配"baz qux"。 - fuzzy
boolean:允许在搜索查询中进行近似匹配。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.contains_any_term(['foo bar']))
示例API响应:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": "foo bar baz"
// ... 其余属性
},
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000001",
"restaurantName": "bar baz"
// ... 其余属性
}
]
}
包含所有词 (Contains all terms)¶
仅适用于字符串(String)属性。返回restaurantName包含提供的值中所有空格分隔词(不区分大小写,顺序不限)的示例餐厅(Example Restaurant)。
参数:
- field
string:要使用的属性名称(例如,restaurantName)。 - value
string:要匹配的空格分隔词集。例如,"foo bar"将匹配"hello foo baz bar",但不匹配"foo qux"。 - fuzzy
boolean:允许在搜索查询中进行近似匹配。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.contains_all_terms(['foo bar']))
示例API响应:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": "hello foo baz bar"
// ... 其余属性
}
]
}
按顺序包含所有词 (Contains all terms in order)¶
仅适用于字符串(String)属性。返回restaurantName按提供的顺序包含所有词(不区分大小写)的示例餐厅(Example Restaurant),但这些词必须相邻。
参数:
- field
string:要使用的属性名称(例如,restaurantName)。 - value
string:要匹配的空格分隔词集。例如,"foo bar"将匹配"hello foo bar baz",但不匹配"bar foo qux"。 - fuzzy
boolean:允许在搜索查询中进行近似匹配。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.contains_all_terms_in_order(['foo bar']))
示例API响应:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": "foo bar baz"
// ... 其余属性
}
]
}
范围比较 (Range comparison)¶
仅适用于数值(Numeric)、字符串(String)和日期时间(DateTime)属性。返回ExampleRestaurant.object_type.restaurantName小于某个值的示例餐厅(Example Restaurant)。
参数:
- field
string:要使用的属性名称(例如,restaurantName)。 - value
string:与餐厅名称进行比较的值。
比较类型:
- 小于
< - 大于
> - 小于或等于
<= - 大于或等于
>=
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name < "Restaurant Name")
等于 (Equal to)¶
仅适用于布尔(Boolean)、日期时间(DateTime)、数值(Numeric)和字符串(String)属性。搜索restaurantName等于给定值的示例餐厅(Example Restaurant)。
参数:
- field
string:要使用的属性名称(例如,restaurantName)。 - value
string:与餐厅名称进行相等性检查的值。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name == "Restaurant Name")
示例API响应:
{
"nextPageToken": "v1.000000000000000000000000000000000000000000000000000000000000000000000000",
"data": [
{
"__rid": "ri.phonograph2-objects.main.object.00000000-0000-0000-0000-000000000000",
"__primaryKey": "Restaurant Id",
"restaurantName": "Restaurant Name"
// ... 其余属性
}
]
}
空值检查 (Null check)¶
仅适用于数组(Array)、布尔(Boolean)、日期时间(DateTime)、数值(Numeric)和字符串(String)属性。根据restaurantName的值是否存在来搜索示例餐厅(Example Restaurant)。
参数:
- field
string:要使用的属性名称(例如,restaurantName)。 - value
boolean:餐厅名称是否存在。注意,对于TypeScript SDK,您需要使用not过滤器来检查字段非空。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurant_name.is_null())
非过滤器 (Not filter)¶
返回不满足查询条件的示例餐厅(Example Restaurant)。可以进一步与其他布尔过滤器操作组合。
参数:
- value
SearchQuery:要取反的搜索查询。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(~ExampleRestaurant.object_type.restaurantId.is_null())
与过滤器 (And filter)¶
返回满足所有查询条件的示例餐厅(Example Restaurant)。可以进一步与其他布尔过滤器操作组合。
参数:
- value
SearchQuery[]:要进行与(and)运算的搜索查询集合。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(~ExampleRestaurant.object_type.restaurantId.is_null() & (ExampleRestaurant.restaurantId == '<primaryKey>'))
或过滤器 (Or filter)¶
返回满足任意指定查询条件的示例餐厅(Example Restaurant)。可以进一步与其他布尔过滤器操作组合。
参数:
- value
SearchQuery[]:要进行或(or)运算的搜索查询集合。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
ExampleRestaurantObjectSet = client.ontology.objects.ExampleRestaurant.where(ExampleRestaurant.object_type.restaurantId.is_null() | (ExampleRestaurant.object_type.restaurantId == '<primaryKey>'))
聚合 (Aggregations)¶
对示例餐厅(Example Restaurant)执行聚合操作。
参数:
- aggregation
Aggregation[](可选):要执行的聚合函数集合。使用SDK时,聚合计算可以通过.where与进一步搜索链式组合。 - groupBy
GroupBy[](可选):为聚合结果创建的分组集合。 - where
SearchQuery(可选):对特定属性进行过滤。可能的操作取决于属性的类型。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
numExampleRestaurant = client.ontology.objects.ExampleRestaurant
.where(~ExampleRestaurant.object_type.restaurant_name).is_null())
.group_by(ExampleRestaurant.object_type.restaurant_name).exact())
.count()
.compute()
示例API响应:
{
excludedItems: 0,
data: [{
group: {
"restaurantName": "Restaurant Name"
},
metrics: [
{
name: "count",
value: 100
}
]
}]
}
聚合类型 (Aggregation)¶
近似去重计数 (Approximate distinct)¶
计算restaurantName的近似去重值数量。
参数:
- field
string:要使用的属性名称(例如,restaurantName)。 - name
string(可选):计算计数的别名。默认情况下为"distinctCount"。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
numExampleRestaurant = client.ontology.objects.ExampleRestaurant
.approximate_distinct(ExampleRestaurant.object_type.restaurant_name)
.compute()
# 这等同于上述查询,但使用metric_name作为名称,而不是默认的"distinctCount"
numExampleRestaurant = client.ontology.objects.ExampleRestaurant
.aggregate(
{"metric_name": ExampleRestaurant.object_type.restaurant_name.approximate_distinct()}
)
.compute()
示例API响应:
{
excludedItems: 0,
data: [{
group: {},
metrics: [
{
name: "distinctCount",
value: 100
}
]
}]
}
计数 (Count)¶
计算示例餐厅(Example Restaurant)的总数。
参数:
- name
string(可选):计算计数的别名。默认情况下为count。
示例查询:
numExampleRestaurant = client.ontology.objects.ExampleRestaurant
.count()
.compute()
示例API响应:
{
excludedItems: 0,
data: [{
group: {},
metrics: [
{
name: "count",
value: 100
}
]
}]
}
数值聚合 (Numeric aggregations)¶
仅适用于数值属性。计算示例餐厅(Example Restaurant)数值属性的最大值、最小值、总和或平均值。
参数:
- field string:要使用的属性名称(例如,numberOfReviews)。
- name string(可选):计算值的别名。默认情况下为"avg"。
聚合类型:
- 平均值:
avg() - 最大值:
max() - 最小值:
min() - 总和:
sum()
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
avgExampleRestaurant = client.ontology.objects.ExampleRestaurant
.avg(ExampleRestaurant.object_type.number_of_reviews)
.compute()
# 这等同于上述查询,但使用metric_name作为名称,而不是默认的"avg"
avgExampleRestaurant = client.ontology.objects.ExampleRestaurant
.aggregate(
{"metric_name": ExampleRestaurant.object_type.number_of_reviews.avg()}
)
.compute()
示例API响应:
{
excludedItems: 0,
data: [{
group: {},
metrics: [
{
name: "avg",
value: 100
}
]
}]
}
分组类型 (GroupBy)¶
精确分组 (Exact grouping)¶
按restaurantName的精确值对示例餐厅(Example Restaurant)进行分组。
参数:
- field
string:要使用的属性名称(例如,restaurantName)。 - maxGroupCount
integer(可选):要创建的restaurantName分组最大数量。
示例查询:
from ontology_sdk.ontology.objects import ExampleRestaurant
numExampleRestaurant = client.ontology.objects.ExampleRestaurant
.group_by(ExampleRestaurant.object_type.restaurant_name.exact())
.count()
.compute()
示例API响应:
{
excludedItems: 0,
data: [{
group: {
"restaurantName": "Restaurant Name"
},
metrics: [
{
name: "count",
value: 100
}
]
}]
}