Reading wordnet folder in Google Cloud Application

120 views Asked by At

I have a Scala web application running in GAE. I need to use a Java library -JWI- which requires me to pass a root folder of Wordnet into edu.mit.jwi.Dictionary's constructor.

I thought about putting all Wordnet stuff into Google Cloud Storage, but it doesn't have a concept of a folder at all. So, my question: is there any way to do what I want with Google Cloud Storage or should I use anything else?

2

There are 2 answers

0
Federico Panunzio On BEST ANSWER

You were right when you stated “there is no API in Google Cloud Java library for folder manipulation”. As of today, there’s no folder manipulation for the java client library. You can check the library here

2
Rubén C. On

You can use Google Cloud Storage (GCS), even if gsutil handles subdirectories in a different way, because it behaves as a regular folder and uses the same notation.

I am not sure about how your application works but if I am guessing well:

  • Load the JWI library to your Cloud Shell.
  • Import the library in your Scala application in App Engine flexible. Find an example here on how to call a Java class using Scala.
  • Deploy the application. Following the previous steps, the image deployed will contain the JWI library you need.
  • Load the Wordnet semantic dictionary in a bucket and pass the root folder of Wordnet, in this case a GCS folder, using the Java client library for the Google Cloud Storage API. The “Dictionary” must be downloaded (using a get function) and locally stored while you are using it.

Find here the Java client library documentation for Cloud Storage. You might need more functions than the ones below which I have written for you, to create a bucket, upload a file and download it.

package com.example.storage;

// Imports the Google Cloud client library
import com.google.cloud.storage.Acl;
import com.google.cloud.storage.Acl.Role;
import com.google.cloud.storage.Acl.User;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

public class QuickstartSample {
  public static void main(String... args) throws Exception {
    // Instantiates a client
    Storage storage = StorageOptions.getDefaultInstance().getService();

    // The name for the new bucket
    String bucketName = args[0];  // "my-new-bucket";

    // Creates the new bucket
    Bucket bucket = storage.create(BucketInfo.of(bucketName));

    System.out.printf("Bucket %s created.%n", bucket.getName());


    // [START uploadFile]

    // Object name
    String fileName="filename.ext";

    // Create file inside the bucket
    BlobInfo blobInfo =
        storage.create(
            BlobInfo
                .newBuilder(bucketName, fileName)
                // Modify access list to allow all users with link to read file
                .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
                .build()
                // other options required
                );
    // return the public download link
    blobInfo.getMediaLink();

    // [END uploadFile]


    // Copy file from a bucket
    String blobName = "filename.ext";
    BlobId blobId = BlobId.of(bucketName, blobName);
    Blob blob = storage.get(blobId);
  }

Finally, find here how to compile the code and running it:

mvn clean package -DskipTests

mvn exec:java -Dexec.mainClass=com.example.storage.QuickstartSample -Dexec.args="bucketName"