Details
-
Bug
-
Resolution: Unresolved
-
Major
-
Mobile 2.8, Mobile 3.0, Mobile 3.1
-
None
-
0
Description
Hi,
[Code snippet exposed in CB Lite documentation (2.8+) page|http://example.com] for Predictive Query seems buggy:
Map<String, Object> inputProperties = new HashMap<>(); |
inputProperties.put("photo", Expression.property("photo")); |
Expression input = Expression.map(inputProperties);
|
PredictionFunction prediction = PredictiveModel.predict("ImageClassifier", input); |
Query query = QueryBuilder
|
.select(SelectResult.all())
|
.from(DataSource.database(database))
|
.where(Expression.property("label").equalTo(Expression.string("car")) |
.and(Expression.property("probability").greaterThanOrEqualTo(Expression.doubleValue(0.8)))); |
// Run the query.
|
ResultSet result = query.execute();
|
Log.d(TAG, "Number of rows: " + result.allResults().size()); |
Even if the
PredictionFunction prediction = PredictiveModel.predict("ImageClassifier", input); |
has been defined, after that, it is NOT used in the following Query (as it should be).
Whereas in the Swift equivalent code snippet, we have:
let input = Expression.dictionary(["photo": Expression.property("photo")]) |
let prediction = PredictiveModel.predict(model: "ImageClassifier", input: input) |
let query = QueryBuilder
|
.select(SelectResult.all())
|
.from(DataSource.database(database))
|
.where(
|
prediction.property("label").equalTo(Expression.string("car")) |
.and(
|
prediction.property("probablity") |
.greaterThanOrEqualTo(Expression.double(0.8)) |
)
|
)
|
// Run the query.
|
do { |
let result = try query.execute() |
print("Number of rows :: \(result.allResults().count)") |
} catch { |
fatalError("Error running the query") |
}
|
and "prediction" variable IS used inside the query, i.e. :
prediction.property("label").equalTo(Expression.string("car") |
Note: same error for Java code snippet : see
https://docs.couchbase.com/couchbase-lite/2.8/java/query-predictive.html#run-a-prediction-query
and