Google vision api text detection - text

I am using google vision api to recognise text from image. The image in Japanese language.
But response is not in Japanese language it is in English. Can any body tell me how to change english to Japanese.

Add a language hint in the AnnotateImageRequest. For example, in C#:
var responses = vision.Images.Annotate(
new BatchAnnotateImagesRequest()
{
Requests = new[] {
new AnnotateImageRequest() {
Features = new [] { new Feature() { Type =
"TEXT_DETECTION"}},
Image = new Image() { Content = imageContent },
ImageContext = new ImageContext()
{
LanguageHints = new string[] { "ja" }
}
}
}
}).Execute();

Try Type "DOCUMENT_TEXT_DETECTION" instead of "TEXT_DETECTION",
For example (in Java),
Feature feat = Feature.newBuilder().setType(Type.DOCUMENT_TEXT_DETECTION).build();

Related

SharePoint Onlinie - Create Drive using graph service client

I am working on one project where I've to create a drive (document library) on SharePoint in not exists.
Using following code:
var newRRRDrive = new Drive
{
Name = "RRRR-Prod1",
Description = "Holds RRRR files",
AdditionalData = new Dictionary<string, object>()
{
{"#microsoft.graph.conflictBehavior","rename"}
}
};
var newDrive = await graphClient
.Sites[site.Id]
.Drives
.Request()
.AddAsync(newRRRDrive);
But this is throwing exception that the request is invalid. I don't know what I doing wrong here.. Any suggestions?
Code: invalidRequest
Message: Invalid request
Inner error:
AdditionalData:
date: 2021-05-30T20:57:40
request-id: ec6ddddddddddddddd0f72d91c8e
client-request-id: ec6ddddddddddddddddddddddddddddddddd
ClientRequestId: ec6dedddddddddddddddddddddddddddddddddddddddddddd
Adding image after implementing soln by Michael
enter image description here
To create a new document library, you can perform the same call as mentioned in the create list instead of using the genericList template value. Use the documentLibrary value.
POST /sites/{site-id}/lists
Content-Type: application/json
{
"displayName": "YourLibraryName",
"list": {
"template": "documentLibrary"
}
}
C# code
var list = new List
{
DisplayName = "Books",
ListInfo = new ListInfo
{
Template = "documentLibrary"
}
};
await graphClient.Sites["{site-id}"].Lists
.Request()
.AddAsync(list);

How to set output contexts while creating a intent in dialogflow PHP?

I am trying to set output context to a particular intent via v2 create intent API.
Please check my code.
use Google\Cloud\Dialogflow\V2\SessionsClient;
use Google\Cloud\Dialogflow\V2\TextInput;
use Google\Cloud\Dialogflow\V2\QueryInput;
use Google\Cloud\Dialogflow\V2\IntentsClient;
use Google\Cloud\Dialogflow\V2\Intent_TrainingPhrase_Part;
use Google\Cloud\Dialogflow\V2\Intent_TrainingPhrase;
use Google\Cloud\Dialogflow\V2\Intent_Message_Text;
use Google\Cloud\Dialogflow\V2\Intent_Message;
use Google\Cloud\Dialogflow\V2\Intent;
use Google\Cloud\Dialogflow\V2\Context;
use Google\Cloud\Dialogflow\V2\ContextsClient;
private function intent_create(){
putenv('GOOGLE_APPLICATION_CREDENTIALS='.getcwd() . '/strive_stage.json');
$intentsClient = new IntentsClient();
/** Create Intent **/
$disaplayName = "Where is Goa";
$utterances = ["Goa", "Where is Goa"];
// prepare training phrases for intent
$trainingPhrases = [];
foreach ($utterances as $trainingPhrasePart) {
$part = new Intent_TrainingPhrase_Part();
$part->setText($trainingPhrasePart);
// create new training phrase for each provided part
$trainingPhrase = new Intent_TrainingPhrase();
$trainingPhrase->setParts([$part]);
$trainingPhrases[] = $trainingPhrase;
}
$messageTexts = 'Goa is in India.';
// prepare messages for intent
$text = new Intent_Message_Text();
$text->setText([$messageTexts]);
$message = new Intent_Message();
$message->setText($text);
$createIntentObject = $intentsClient->projectAgentName(env("DIALOG_FLOW_PROJECT_ID"));
// prepare intent
$intent = new Intent();
$intent->setDisplayName($disaplayName);
$intent->setTrainingPhrases($trainingPhrases);
$intent->setMessages([$message]);
$contexts = ['test'];
foreach($contexts as $con){
$contextObj = new Context();
$contextObj->setName($con);
$contextData[] = $contextObj;
$intent->setOutputContexts($contextData);
}
// $intent->getOutputContexts('test');
//dd($intent);
$response = $intentsClient->createIntent($createIntentObject, $intent);
printf('Intent created: %s' . PHP_EOL, $response->getName());
}
I am getting error message
{
"message": "com.google.apps.framework.request.BadRequestException: Resource name does not match format 'projects/{project_id}/agent/sessions/{session_id}/contexts/{context_id}' or 'projects/{project_id}/locations/{location_id}/agent/sessions/{session_id}/contexts/{context_id}'.",
"code": 3,
"status": "INVALID_ARGUMENT",
"details": []
}
I believe the issue is with the format of storing the output context. Please help me on this.
I had the same issue. The answer is to not put in the bare name, but to have a string of a certain format made
see http://googleapis.github.io/google-cloud-php/#/docs/google-cloud/v0.131.0/dialogflow/v2/intent?method=setOutputContexts
// $projectId your project id
// $sessionId can be anything, I use $sessionId = uniqid();
$uri = "projects/$projectId/agent/sessions/$sessionId/contexts/$con";
$contextObj->setName($uri);
I can see that there are any response about this topic.
I leave here my solution for the next generations
To create a output context you need to create the correct format, for this objetive you can use Context class Google\Cloud\Dialogflow\V2\Context
private function parseoOutputContexts($contexts, $project_id, $lifespan = 5)
{
$newContexts = array();
foreach ($contexts as $context) {
$newContexts[] = new Context(
[
'name' => 'projects/' . $project_id . '/agent/sessions/-/contexts/' . $context,
'lifespan_count' => $lifespan
]
);
}
return $newContexts;
}
And you can use this function to finnaly add the output context to the object Intent.
$dialogflow_intent = new Intent();
$output_contexts = ['output_context_1'. 'output_context_2'];
$output_contexts = $this->parseOutputContexts($output_contexts, '[YOUR_PROJECT_ID]');
$dialogflow_intent->setOutputContexts($output_contexts);

Database of file extensions to file type/language mappings

vscode uses a nice schema for file extension to language mapping:
https://code.visualstudio.com/docs/languages/identifiers
"files.associations": {
"*.myphp": "php"
}
"languages": [{
"id": "java",
"extensions": [ ".java", ".jav" ],
"aliases": [ "Java", "java" ]
}]
Tools like prismjs, have built-in support for hundreds of languages.
But I can't find a database of common extension to language mapping anywhere. Note I don't care about mime types. In my case I want have a built-in (actually, it'd ideally be driven off a webapi) set of mappings.
I've searched the vscode and found the code that deals with the mappings it handles (/src/vs/editor/common/services/languagesRegistry.ts) but it appears to load the mapping from the extensions that are installed.
IOW, I want to generate (or find!) a JSON document using the above schema with all 199 languages that prismjs supports.
Any suggestions?
lang-map, a nodejs module makes it easy to go from either file extension to language or language to supported extensions.
https://github.com/jonschlinkert/lang-map
I've successfully used this to generate a JSON doc using the vscode schema.
Probably aint pretty (not a javascript pro), but it works:
// Imports file-extension to langauge mapping from both
// prismjs and lang-map and outputs a JSON document that
// follows the vscode schema for extension mapping.
// PrismJS language definitions trump for my solution.
const fs = require('fs');
var map = require('lang-map');
var components = require('prismjs/components.js');
// vscode files.associations is not an array. Use a dictionary instead.
var assocDict = {};
var languages = [];
for (var key in components.languages) {
if (components.languages.hasOwnProperty(key) && key != 'meta') {
var language = components.languages[key];
var langTemp = {
id : key
};
// vscode doesn't support title, but I want to use it
if (typeof language.title != 'undefined')
langTemp.title = language.title;
if (typeof language.alias != 'undefined'){
if (Array.isArray(language.alias)){
langTemp.aliases = language.alias;
}
else{
langTemp.aliases = ['.' + language.alias];
}
}
var extensions = [];
map.extensions(key).forEach(ext =>{
// Add it to the extnsions for this langauge defn
extensions.push('.' + ext);
// also add it to the files.associations dictionary
var pattern = '*.' + ext;
var assoc = {
pattern : key
};
assocDict[pattern] = key;
});
langTemp.extensions = extensions;
languages.push(langTemp);
}
}
// create JSON doc conforming to vscode spec. associations is not an array
// languages is
var output = {
'files.associations' : assocDict,
'languages' : languages
};
var file = "../winforms/WinPrint.Core/Properties/languages.json";
fs.writeFile(file, JSON.stringify(output, null, ' '), function (err) {
if (err) {
return console.log(err);
}
console.log("Wrote " + Object.keys(assocDict).length + " file-type associations and " + languages.length + " language defs to " + file);
});
I also found this, which I may just use instead:
https://github.com/blakeembrey/language-map

Sent a picture in a chatbot using botframework

I have a chatbot using the botframework of Microsoft, with my webapp running the chatbot on Azure. How can I return a picture as an answer to a message. We have clients using Skype, Messenger and KiK
Take a look at the docs section on image and file attachments
replyMessage.Attachments.Add(new Attachment()
{
ContentUrl = "https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png",
ContentType = "image/png"
});
Or as JSON:
{
"attachments": [
{
"contentType": "image/png",
"contentUrl": "https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png"
}
]
}
You can also send Rich Cards:
replyMessage.Attachments = new List<Attachment>();
replyMessage.Attachments.Add(new Attachment()
{
Title = "Bender",
TitleLink = "https://en.wikipedia.org/wiki/Bender_(Futurama)",
ThumbnailUrl = "http://www.theoldrobots.com/images62/Bender-18.JPG",
Text = "Bender Bending Rodríguez, commonly known as Bender, is a main character in the animated television series Futurama.",
FallbackText = "Bender: http://www.theoldrobots.com/images62/Bender-18.JPG"
});

How to auto-indent / format groovy script with ACE or CodeMirror

I'm developing a web app which needs an embedded groovy script editor, i tried both with CodeMirror and ACE but neither offers me auto-indent nor formatting.
I fetch the code of the script from the database and then put it on a javascript variable called myScript;
Then with ACE i do this:
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/groovy");
editor.getSession().setUseWrapMode(true);
editor.setShowPrintMargin(false);
editor.setValue(myScript);
and i do it like this with CodeMirror:
var myCodeMirror = CodeMirror(document.body, {
value: myScript,
mode: "groovy",
theme: "monokai",
lineWrapping: true,
lineNumbers: true
});
and the editor works perfect, the problem is that the code that it shows it is not indented nor formatted, and it's pretty ugly. For example:
def reputationMapping = []; def totalReputation = 0; def userReputationResult = message.properties['reputation']; for (row in userReputationResult) { reputationMapping[row[0]] = row[1]; totalReputation = row[1]; }; def computedRank = 0; def reviewResult = message.properties['reviews']; for (row in reviewResult) { if (reputationMapping[row[0]] != null) { def reputation = reputationMapping[row[0]]; computedRank = computedRank + (reputation * row[1]); }; }; message.payload = computedRank;
Can you please help? Thanks.

Resources