Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-11626

Predictive query sample for Android and Java seems not OK

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • Mobile 2.8
    • Mobile 2.8, Mobile 3.0, Mobile 3.1
    • documentation
    • None
    • 0

    Description

      Hi,

      [Code snippet exposed in CB Lite documentation (2.8+) page|http://example.com] for Predictive Query seems buggy:

      https://github.com/couchbase/docs-couchbase-lite/blob/9c8027e0dacea029aacd7214f03db3745b7997ae/modules/android/examples/snippets/app/src/main/java/com/couchbase/code_snippets/Examples.java#L1200-L1213

       

       

      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 

      https://github.com/couchbase/docs-couchbase-lite/blob/9c8027e0dacea029aacd7214f03db3745b7997ae/modules/java/examples/code_snippets/Examples.java#L1696-L1709 

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            elliot.hunter Elliot Hunter
            fabrice.leray Fabrice Leray
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty