Search in sources :

Example 1 with Product

use of com.google.cloud.vision.v1.Product in project cuba by cuba-platform.

the class DataManagerTransactionalUsageTest method testSecureWithProgrammaticTx.

@Test
public void testSecureWithProgrammaticTx() {
    SaleProcessor processor = AppBeans.get("test_SaleProcessor");
    Id<OrderLine, UUID> orderLineId = processor.sellSecureWithProgrammaticTx("abc", 10);
    Product product1 = dataManager.load(Product.class).query("select p from sales1$Product p where p.name = :name").parameter("name", "abc").one();
    assertEquals(90, (int) product1.getQuantity());
    Product product2 = dataManager.create(Product.class);
    product2.setName("def");
    product2.setQuantity(100);
    dataManager.commit(product2);
    OrderLine orderLine = dataManager.load(orderLineId).view("with-product").one();
    orderLine.setProduct(product2);
    dataManager.commit(orderLine);
    Product changedProduct1 = dataManager.load(Id.of(product1)).one();
    assertEquals(100, (int) changedProduct1.getQuantity());
    Product changedProduct2 = dataManager.load(Id.of(product2)).one();
    assertEquals(90, (int) changedProduct2.getQuantity());
}
Also used : OrderLine(com.haulmont.cuba.testmodel.sales_1.OrderLine) Product(com.haulmont.cuba.testmodel.sales_1.Product) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 2 with Product

use of com.google.cloud.vision.v1.Product in project narchy by automenta.

the class BooleanChallenge method event.

@Override
public void event(Class event, Object[] arguments) {
    if (!(arguments[0] instanceof Task))
        return;
    Task answer = (Task) arguments[0];
    if (!answer.isJudgment())
        return;
    if (answer.isInput()) {
        // this is a repetition of something explicitly input
        return;
    }
    // if (!started) {
    // if (answer.getTerm().toString().equals(startChallenge)) {
    // started = true;
    // }
    // else {
    // return;
    // }
    // }
    // for now, assume the qustion term is answer term
    Term qterm = answer.getTerm();
    if (answerProvided.contains(qterm)) {
        return;
    }
    if (answer.getConfidence() < confThreshold)
        return;
    Term t = answer.getTerm();
    if (t instanceof Inheritance) {
        Term subj = ((Inheritance) t).getSubject();
        Term pred = ((Inheritance) t).getPredicate();
        if ((subj instanceof SetExt) && (((SetExt) subj).length() == 1))
            subj = ((Compound) subj).term[0];
        if (subj instanceof Product) {
            Product p = (Product) subj;
            int[] n = n(p, 3);
            if (n != null) {
                boolean correct = false;
                switch(pred.toString()) {
                    case "and":
                        correct = evalAnd(n);
                        break;
                    case "or":
                        correct = evalOr(n);
                        break;
                    case "xor":
                        correct = evalXor(n);
                        break;
                    // case "not": correct = evalNot(n); break;
                    default:
                        return;
                }
                float freq = answer.getFrequency();
                float conf = answer.getConfidence();
                if (freq < freqThresh) {
                    // invert
                    correct = !correct;
                    freq = 1f - freq;
                }
                if (freq < (1.0 - freqThresh)) {
                    // not clear 0 or 1
                    return;
                }
                addScore(qterm, answer, correct, freq * conf);
                if (!correct) {
                    System.err.println(answer.getExplanation());
                    if (failOnError)
                        System.exit(1);
                    // give correct answer
                    if (correctFeedback) {
                        // String c = getTerm(n[0], n[1], pred.toString(), not(n[2])) + ('.');
                        Term fc = nar.term(getTerm(n[0], n[1], pred.toString(), n[2]));
                        String c = "(--," + fc + ("). %1.00;" + n2(inputConf) + "%");
                        nar.input(c);
                        answerProvided.add(fc);
                        questionScores.remove(fc);
                    }
                }
            }
        }
    }
}
Also used : Inheritance(nars.nal.nal1.Inheritance) SetExt(nars.nal.nal3.SetExt) Product(nars.nal.nal4.Product) Term(nars.term.Term)

Example 3 with Product

use of com.google.cloud.vision.v1.Product in project java-vision by googleapis.

the class ProductManagement method createProduct.

// [START vision_product_search_create_product]
/**
 * Create one product.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @param productDisplayName - Display name of the product.
 * @param productCategory - Category of the product.
 * @throws IOException - on I/O errors.
 */
public static void createProduct(String projectId, String computeRegion, String productId, String productDisplayName, String productCategory) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // A resource that represents Google Cloud Platform location.
        String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion);
        // Create a product with the product specification in the region.
        // Multiple labels are also supported.
        Product myProduct = Product.newBuilder().setName(productId).setDisplayName(productDisplayName).setProductCategory(productCategory).build();
        Product product = client.createProduct(formattedParent, myProduct, productId);
        // Display the product information
        System.out.println(String.format("Product name: %s", product.getName()));
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) Product(com.google.cloud.vision.v1.Product)

Example 4 with Product

use of com.google.cloud.vision.v1.Product in project java-vision by googleapis.

the class ProductManagement method updateProductLabels.

// [END vision_product_search_get_product]
// [START vision_product_search_update_product_labels]
/**
 * Update the product labels.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId -Id of the product.
 * @param productLabels - Labels of the product.
 * @throws IOException - on I/O errors.
 */
public static void updateProductLabels(String projectId, String computeRegion, String productId, String productLabels) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the product.
        String formattedName = ProductSearchClient.formatProductName(projectId, computeRegion, productId);
        // Set product name, product labels and product display name.
        // Multiple labels are also supported.
        Product product = Product.newBuilder().setName(formattedName).addProductLabels(KeyValue.newBuilder().setKey(productLabels.split(",")[0].split("=")[0]).setValue(productLabels.split(",")[0].split("=")[1]).build()).build();
        // Set product update field name.
        FieldMask updateMask = FieldMask.newBuilder().addPaths("product_labels").build();
        // Update the product.
        Product updatedProduct = client.updateProduct(product, updateMask);
        // Display the product information
        System.out.println(String.format("Product name: %s", updatedProduct.getName()));
        System.out.println(String.format("Updated product labels: "));
        for (Product.KeyValue element : updatedProduct.getProductLabelsList()) {
            System.out.println(String.format("%s: %s", element.getKey(), element.getValue()));
        }
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) Product(com.google.cloud.vision.v1.Product) KeyValue(com.google.cloud.vision.v1.Product.KeyValue) FieldMask(com.google.protobuf.FieldMask)

Example 5 with Product

use of com.google.cloud.vision.v1.Product in project java-vision by googleapis.

the class ProductManagement method getProduct.

// [END vision_product_search_list_products]
// [START vision_product_search_get_product]
/**
 * Get information about a product.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @throws IOException - on I/O errors.
 */
public static void getProduct(String projectId, String computeRegion, String productId) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the product.
        String formattedName = ProductSearchClient.formatProductName(projectId, computeRegion, productId);
        // Get complete detail of the product.
        Product product = client.getProduct(formattedName);
        // Display the product information
        System.out.println(String.format("Product name: %s", product.getName()));
        System.out.println(String.format("Product id: %s", product.getName().substring(product.getName().lastIndexOf('/') + 1)));
        System.out.println(String.format("Product display name: %s", product.getDisplayName()));
        System.out.println(String.format("Product description: %s", product.getDescription()));
        System.out.println(String.format("Product category: %s", product.getProductCategory()));
        System.out.println(String.format("Product labels: "));
        for (Product.KeyValue element : product.getProductLabelsList()) {
            System.out.println(String.format("%s: %s", element.getKey(), element.getValue()));
        }
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) Product(com.google.cloud.vision.v1.Product) KeyValue(com.google.cloud.vision.v1.Product.KeyValue)

Aggregations

ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)19 Product (com.google.cloud.vision.v1.Product)10 Test (org.junit.Test)9 ReferenceImage (com.google.cloud.vision.v1.ReferenceImage)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 Product (com.haulmont.cuba.testmodel.sales_1.Product)5 Test (org.junit.jupiter.api.Test)5 ProductSet (com.google.cloud.vision.v1.ProductSet)4 QueryRunner (com.haulmont.bali.db.QueryRunner)3 Id (com.haulmont.cuba.core.entity.contracts.Id)3 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)3 TestContainer (com.haulmont.cuba.testsupport.TestContainer)3 Assertions (org.junit.jupiter.api.Assertions)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)3 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)2 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)2 BatchOperationMetadata (com.google.cloud.vision.v1.BatchOperationMetadata)2 CreateProductSetRequest (com.google.cloud.vision.v1.CreateProductSetRequest)2 Feature (com.google.cloud.vision.v1.Feature)2