Create Dynamic link of 8 Characters Length - firebase

const link = await dynamicLinks().buildShortLink({
link: share_link,
android: {
packageName: 'com.beffel'
},
ios: {
bundleId: 'com.beffel'
},
domainUriPrefix:'https://link.page.link'
});
Using this code for making a Short link But i want to make it 8 characters length Short link. So i am not getting how can i define 10 character length in it. As this code is working correctly but not generating length of 10 characters. How can i generate it please let me know how can make it done.

Related

Google Translate API: Enable word conversion

I'm translating a list of words using google translate API, however I noticed that for words that it cannot translate, it returns the same word in the source language.
For example, let's observe the following request of word array conversion from English to Hebrew:
const response = await axios.post<TranslateResponse>(`https://translation.googleapis.com/language/translate/v2?key=xxxxxxx`,
{
"q": ["SUNFINSH", "DOG"],
"source": "en",
"target": "he",
"format": "text"
});
The returned object is
{"data":{"translations":[{"translatedText":"SUNFINSH"},{"translatedText":"כֶּלֶב"}]}}
in the above example, you can see it translated "DOG", but could not translate "SUNFISH".
However, if I go to translate.google.com, and type in "SUNFISH", even though it does not translate it on the right panel UI, it does offer kind of a "literal" translation, as if it can simply convert the word to how it sounds in Hebrew.
The question is, how can I get the same result using the Google Translate API?
You may try and change "SUNFISH" into "sunfish" and it will return the expected output same as the screenshot you provided using the Google Translate UI.
As seen in the screenshot provided using the Google Translate UI, Google converted "SUNFISH" into "sunfish" first and then from there, it translated it to Hebrew.
Please see the screenshot of my testing.
I also tested using "Sunfish" and still got the expected result in hebrew.
In addition, as mentioned in this official google support forum,
Google Translate must be case sensitive as no two languages follow the same Capitalization rule.
Below is my sample code used in testing for your reference.
// Imports the Google Cloud client library
const {Translate} = require('#google-cloud/translate').v2;
// Creates a client
const translate = new Translate();
const text = ['sunfish', 'DOG'];
const target = 'he';
async function translateText() {
// Translates the text into the target language. "text" can be a string for
// translating a single piece of text, or an array of strings for translating
// multiple texts.
let [translations] = await translate.translate(text, target);
translations = Array.isArray(translations) ? translations : [translations];
console.log('Translations:');
translations.forEach((translation, i) => {
console.log(`${text[i]} => (${target}) ${translation}`);
});
}
translateText();

Metascraper Consolidated Data

I'm using metascraper in a project I'm working on. I'm passing in custom rules into the contructor. It's actually scraping actual content from the page its scraping. The problem is, is that it appears to be finding every tag that matches the CSS selector, and combining all of the text() content from every tag on the page. I checked metascraper website and github and couldn't find any information about an option that changes this kind of mode/behavior. I made sure that each scrape request creates a new instance of metascraper in case it was just using the same member variables across multiple uses of the object, but that didn't seem to do anything. Any thoughts?
Edit: Also, ideally, metascraper would return an array of arrays of sets of selectors it finds. I have 4 selectors in a group that appear in groups throughout a page. I need it to iterate over the selectors in order, until it cannot find any more instances of the 1st selector (aka the groups have stopped appearing on the page).
type4: async (page: Page): Promise<Extract[]> => {
const html = await page.content()
const url = await page.url()
const type4MetascraperInstance = createType4MetaScraperInstance()
const metadata = await type4MetascraperInstance({ html: html, url: url })
console.log('metadata: ', metadata)
const extract: Extract[] = [{
fingerprint: 'type4',
author: metadata.author,
body: metadata.description,
images: null,
logo: null,
product: null,
rating: null,
title: metadata.title,
videos: null
}]
return extract
}
The function for creating the Type4 metascraper instance is:
function createType4MetaScraperInstance() {
const toDescription = toRule(description)
const toAuthor = toRule(author)
const toTitle = toRule(title, { removeSeparator: false })
const type4MetaScraperInstance = metaScraper([ {
author: [
toAuthor($ => $('.a-profile-name').text()),
],
title: [
toTitle($ => $('a[data-hook="review-title"] > span').text()),
],
description: [
toDescription($ => $('.review-text-content').text()),
]
} ])
return type4MetaScraperInstance
}
I decided to architect a different solution here that uses a python script to properly parse reviews, and it will need to read/write to google cloud datastore. Some suggestions people provided were to write my own calls to cheeriojs (https://cheerio.js.org/), instead of using metascraper at all.

How to extract params from received link in react native firebase dynamiclink?

I tried to migrate from react navigation deeplinks to firebase dynamic linking using this library (react-native-firebase).
I have set up everthing and links are being generated and received on the app. However, is there any way to extract the params sent in the link properly using this library?. Currenty this is my code for handling received link:
handleDynamicLink = () => {
firebase
.links()
.getInitialLink()
.then((url) => {
console.tron.log('link is ', url);
})
.catch((error) => {
console.tron.log(error);
});
};
The url received is
https://links.dev.customdomain.in/?link=products%2F1122
I want to extract the product id 1122 from the url. The only way for me right now is to parse the string and manually extract the relevant params. Unlike in react navigation deeplinks where I used to specify the path, like
Product: {
screen: Product,
path: 'customdomain/products/:slug',
},
Where the slug or id data used to pass as navigation param in the respective screen. Am I missing something? How can I pass mutliple params this way?
Point 2 in this link here says:
The response contains the URL string only.
This means that the firebase.links().getInitialLink() method does not return query parameters, at least as at the time of writing this (v5.5.5). To add your paramaters, you should use a URL with your query param as part of the URL. What I mean is this
Use https://links.dev.customdomain.in/link/products/1122
and use Regex to extract the product id which is of interest to you. This is what works for me and I hope it helps.

Google Cloud Vision Raw JSON Response

When trying out google cloud vision with the drag and drop Try Drag and Drop, the last tab has raw JSON. What parameter do we need to pass to get that data?
I'm currently doing DOCUMENT_TEXT_DETECTION but it only gives data at the level of words and not of individual characters.
Edit: I modified this code vision test and changed the feature ...
feature := &vision.Feature{
Type: "DOCUMENT_TEXT_DETECTION",
}
and the printing to ...
body, err := json.Marshal(res)
fmt.Println(string(body))
I'm only seeing textAnnotations in the output.
The JSON file contains different things like text, locations and etc etc, Your concern is about getting full text.
Here I am adding a Python code, it says that you can get the full text by rendering the JSON file, you will find your required result using data['fullTextAnnotation']['text'], and you can get characters by breaking this file into smaller chunks and I guess JSON file has individual characters in it but I have never worked on it.
import json
from pprint import pprint
data = json.load(open('File Path'))
pprint(data['fullTextAnnotation']['text'])
Well, if you check properly there are various things available in that last tab containing raw JSON.
Based on your requirements you can fetch any of them.
From the response that you get from DOCUMENT_TEXT_DETECTION, you can fetch text_annotations, full_text_annotations, etc.
From text_annotations, you can fetch description, language of entire text, each words of texts, numeric digits, special characters and their respective co-ordinates.
From full_text_annotations, you can fetch pages, blocks of data, paragraphs, and individual characters, with their respective co-ordinates and confidence score.
Using the same code template you are using in Go language:
Search “type Feature struct” in the browser in this page. You can see the following feature types and descriptions:
// Type: The feature type.
//
// Possible values:
// "TYPE_UNSPECIFIED" - Unspecified feature type.
// "FACE_DETECTION" - Run face detection.
// "LANDMARK_DETECTION" - Run landmark detection.
// "LOGO_DETECTION" - Run logo detection.
// "LABEL_DETECTION" - Run label detection.
// "TEXT_DETECTION" - Run text detection / optical character
// recognition (OCR). Text detection
// is optimized for areas of text within a larger image; if the image
// is
// a document, use `DOCUMENT_TEXT_DETECTION` instead.
// "DOCUMENT_TEXT_DETECTION" - Run dense text document OCR. Takes
// precedence when both
// `DOCUMENT_TEXT_DETECTION` and `TEXT_DETECTION` are present.
// "SAFE_SEARCH_DETECTION" - Run Safe Search to detect potentially
// unsafe
// or undesirable content.
// "IMAGE_PROPERTIES" - Compute a set of image properties, such as
// the
// image's dominant colors.
// "CROP_HINTS" - Run crop hints.
// "WEB_DETECTION" - Run web detection.
There is not an option to directly show the JSON tab contents. The JSON tab contents are the addition of all the tabs “output”. Users tend to ask just for one. For example, when someone is analyzing faces is not interested in text detection.
If you need more than one, you can obtain multiple features outputs by “adding” the result of all the possible values together. Based on the facts mentioned, I have added the following lines to your code:
feature2 := &vision.Feature{
Type: "LABEL_DETECTION",
MaxResults: 10,
}
req2 := &vision.AnnotateImageRequest{
Image: img,
Features: []*vision.Feature{feature2},
}
batch2 := &vision.BatchAnnotateImagesRequest{
Requests: []*vision.AnnotateImageRequest{req2},
}
res2, err := svc.Images.Annotate(batch2).Do()
if err != nil {
log.Fatal(err)
}
body2, err := json.Marshal(res2)
fmt.Println(string(body2))
I have tested it and works. You should add this block of code for all the features in which you are interested. If you intend to add many of them, I would suggest to create a function/loop to avoid repeating code.
Anyway, I suggest you to fulfill the request here in order to exactly obtain the JSON output (that gives data at the level of words or letters) through calling the API instead of using a client library. I have used the next code to obtain the bounding box for the numbers of my interest:
{
"requests":
[
{
"features":
[
{
"type":
""
"maxResults":
-- add a property --model
}
{
"type":
""
-- add a property --maxResultsmodel
}
]
"image":
{
"source":
{
"gcsImageUri":
""
-- add a property --imageUri
}
-- add a property --content
}
-- add a property --imageContext
}
]
-- add a property --
}

Removing of unwanted line returns/breaks in a csv export in openUI5

I'm learning OpenUI5 as part as my new job/internship and I've hit a snag in the product that I'm working on. The exported csv is correct as far as everything that we want is properly exported but if the string/input of an item contains a new line character or is ended with the enter key it breaks the csv export but the model within the table still displays correctly.
description.replace(/(\r\n|\n|\r)/gm," ");
Is what would work to remove any line returns or enters being found within the string but the way that data is bound within this application is within this type of structure:
exportType : new sap.ui.core.util.ExportTypeCSV({
separatorChar : "," //;
}),
models : table.getModel(),
rows : {
path : "/interactions"
},
columns : [ {
name : "description",
template : {
content : "{description}"
}
}] // There is more listings after this but it's not important
// ... more items here
}); // End of the bounded data to export
As stated previously, my item 'description' can contain new line characters but when I convert to to csv in the export, it will do something like this:
90000440,Information Protection Policy,Scene1_QuestionDraw01_Slide1_TrueFalse_0_0,The Information Security Officer is responsible for the review and revision of this policy.
(True or False),false,false,1,1
There isn't supposed to be an actual line return within the outputted csv but since there is a new line character or line return within the description, it outputs one in the export.
Any amount of help that leads to me solving this issue would be fantastic.
Thank you, Jordan.
The best way would be to be able to use string delimiters as indicated in the comment by criticalfix. This normally works by default, see the following code from the current UI5 codebase: github. It might be that you have an UI5 version that does not cover this, because this was fixed last year in summer (see this commit). You can see the versions which contain this commit in the commit itself (immediately above the author line).
If you cannot upgrade to a version that contains this commit, then maybe your first idea of replacing the newlines would be appropriate. You can use a formatter in conjunction with your binding to remove the newlines:
// all the stuff before
columns : [ {
name : "description",
template : {
content : {
path: "description",
formatter: function (description) {
return description.replace(/(\r\n|\n|\r)/gm," ");
}
}
}
}]

Resources