gcp_storage

package
v0.0.0-...-cc973eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFileNameFromBucket

func GetFileNameFromBucket(ctx context.Context, gcsBucket, path string, client *storage.Client) (string, error)

GetFileNameFromBucket gets a file name from a bucket

func GetFileNamesFromBucket

func GetFileNamesFromBucket(ctx context.Context, gcsBucket, path string, client *storage.Client) ([]string, error)

func GetObjectHandlesFromBucket

func GetObjectHandlesFromBucket(ctx context.Context, gcsBucket, path string, client *storage.Client) ([]*storage.ObjectAttrs, error)

GetObjectHandlesFromBucket returns a list of object handles from a given bucket and path

func RetrieveText

func RetrieveText(response *DocumentDetectResponse) (string, error)

RetrieveText parses the JSON and retrieves only the relevant text elements

func UploadTextToGCS

func UploadTextToGCS(ctx context.Context, text string, storageBucket, bucketPath string, client *storage.Client)

UploadToGCS

Types

type DocumentDetectResponse

type DocumentDetectResponse struct {
	InputConfig struct {
		GcsSource struct {
			URI string `json:"uri"`
		} `json:"gcsSource"`
		MimeType string `json:"mimeType"`
	} `json:"inputConfig"`
	Responses []struct {
		Context struct {
			PageNumber int    `json:"pageNumber"`
			URI        string `json:"uri"`
		} `json:"context"`
		FullTextAnnotation struct {
			Pages []struct {
				Blocks []struct {
					BlockType   string `json:"blockType"`
					BoundingBox struct {
						NormalizedVertices []struct {
							X float64 `json:"x"`
							Y float64 `json:"y"`
						} `json:"normalizedVertices"`
					} `json:"boundingBox"`
					Confidence float64 `json:"confidence"`
					Paragraphs []struct {
						BoundingBox struct {
							NormalizedVertices []struct {
								X float64 `json:"x"`
								Y float64 `json:"y"`
							} `json:"normalizedVertices"`
						} `json:"boundingBox"`
						Confidence float64 `json:"confidence"`
						Words      []struct {
							BoundingBox struct {
								NormalizedVertices []struct {
									X float64 `json:"x"`
									Y float64 `json:"y"`
								} `json:"normalizedVertices"`
							} `json:"boundingBox"`
							Confidence float64 `json:"confidence"`
							Property   struct {
								DetectedLanguages []struct {
									LanguageCode string `json:"languageCode"`
								} `json:"detectedLanguages"`
							} `json:"property"`
							Symbols []struct {
								Confidence float64 `json:"confidence"`
								Property   struct {
									DetectedLanguages []struct {
										LanguageCode string `json:"languageCode"`
									} `json:"detectedLanguages"`
								} `json:"property"`
								Text string `json:"text"`
							} `json:"symbols"`
						} `json:"words"`
					} `json:"paragraphs"`
				} `json:"blocks"`
				Height   int `json:"height"`
				Property struct {
					DetectedLanguages []struct {
						Confidence   float64 `json:"confidence"`
						LanguageCode string  `json:"languageCode"`
					} `json:"detectedLanguages"`
				} `json:"property"`
				Width int `json:"width"`
			} `json:"-"`
			Text string `json:"text"`
		} `json:"fullTextAnnotation"`
	} `json:"responses"`
}

DocumentDetectResponse represents the output upon analyzing a document. The fulltext annotations are omitted to save space.

func Download

func Download(ctx context.Context, gcsBucket, path string, client *storage.Client) (*DocumentDetectResponse, error)

Download retrieves the item from cloud storage. The MIME type in Cloud storage must be application/json otherwise The application will crash

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL