Google Cloud Datastore - Different results of query by Kind and query by GQL - google-cloud-datastore

I have 2 types of query, by Kind and by GQL
$query = $datastore
->query()
->kind('files')
->filter('tags','=','texture')
->filter('tags','=','newspaper')
->start($pageCursor);
This gives more results than GQL query:
$query = $datastore
->gqlQuery
("SELECT *
FROM files
where tags='texture' and tags='newspaper'",
['allowLiterals' => true]
);
Why are their results not the same?
My results of query by Kind: https://drive.google.com/open?id=1r-Tonqs1ld4bKo0woIcR_UrMUTc1em0D
If I use query by GQL, only 4 results are found
Update
You can follow this topic: https://github.com/googleapis/google-cloud-php/issues/1696

It is very difficult to find your error without seeing your code, try to provide more details in your next questions.
I have used your example and all works as expected. The output of this script is:
Query by kind retrieves 19 results
Query by GQL retrieves 19 results
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
# Imports the Google Cloud client library
use Google\Cloud\Datastore\DatastoreClient;
# Your Google Cloud Platform project ID
$projectId = 'YOUR-PROJECT-ID';
$datastore = new DatastoreClient([
'projectId' => $projectId
]);
$titles = ['man sitting near door', 'way reading paper', 'scattered magazines', 'grayscale ', 'photography of kanji text', 'texture: vintage newspaper', 'wall floor recycle light simple', 'old newspaper texture', 'Mockup Old Paper Color ', 'Mockup Journal.', 'Old Newspaper Texture', 'Triangle Geometric Graphic Pattern Template', 'paperboard carton surface beige plain', 'paperboard simple fiber dusty texture', 'Designer Workspace', 'craft texture brown journal note', 'Brown texture', 'Newspaper collage texture', 'Texture Newspaper'];
$tags = ['newspaper, texture, space for copy, space, cover, white, textured, antique, text, press, write, worn, backdrop, surface, old, scratch, brown, ancient, light, background, vintage, effect, letter, space for text, template, blank, rough, color, line, book, pattern, stain, paper, design, copy, dirty, grunge, copyspace, aged, retro, banner, abstract, message, print, smudge, material, grungy, wooden, wall, age, chinese, china, chinese newspaper',
'world, war, newspaper, texture, history, grunge, pattern, american, war, battle', 'basket, yellow building, shop, colour, wallpaper, texture, misc, wallpaper, urban, bicycle, morning, sidewalk, asian, newspaper, yellow, street, bike, man, tree, china, bycicle',
'man, boy, male, card, paper, decoration, woman, child, smile, torn, wall, paper, poster, texture, old, affiche wall advert wallpaper portugal wall poster erosion used print urban, newspaper',
'white, cloud, house, bw, black and white, pattern, light, street, silhouette, texture, calligraphy, composition, japanese, japan, newspaper, character, wall, wall paper, wall art, poster, black and white, png images',
'newspaper, texture, space for copy, space, cover, white, textured, antique, text, press, write, worn, backdrop, surface, old, scratch, brown, ancient, light, background, vintage, effect, letter, space for text, template, blank, rough, color, line, book, pattern, stain, paper, design, copy, dirty, grunge, copyspace, aged, retro, banner, abstract, message, print, smudge, material, grungy, wooden, wall, vintage newspaper',
'background, pattern, vintage, texture, paper, light, space, grunge, wall, note, flat, old paper, paper texture, desk, newspaper, recycle, natural, document, nature background, clean',
'newspaper, texture, space for copy, space, cover, white, textured, antique, text, press, write, worn, backdrop, surface, old, scratch, brown, ancient, light, background, vintage, effect, letter, space for text, template, blank, rough, color, line, book, pattern, stain, paper, design, copy, dirty, grunge, copyspace, aged, retro, banner, abstract, message, print, smudge, material, grungy, wooden, wall, age, old paper',
'newspaper, cut, paper, kraft, cardboard, mockup, old, slip, ad, advertisement, advertising, ancient, announcement, antique, backdrop, background, banner, blank, border, card, christmas, communication, design, dirty, edge, empty, grunge, illustration, information, label, letter, message, note, page, parchment, pattern, poster, red, ripped, shadow, sticker, tag, template, texture, torn, vector, vintage, wallpaper, web, white',
'leather, magazine, mockup, book, black, spread, page, double, brochure, blank, reading, journal, template, a4, holding, hand, newspaper, front, leaflet, person, back, binding, softcover, big, pamphlet, album, business, clear, dark, design, desk, display, document, glossy, grey, hard, hardcover, layout, ledger, mag, mock up, news, opened, paper, paperback, print, sheet, showing, soft, text, texture',
'newspaper, texture, space for copy, space, cover, white, textured, antique, text, press, write, worn, backdrop, surface, old, scratch, brown, ancient, light, background, vintage, effect, letter, space for text, template, blank, rough, color, line, book, pattern, stain, paper, design, copy, dirty, grunge, copyspace, aged, retro, banner, abstract, message, print, smudge, material, grungy, wooden, wall, age',
'pattern, people, texture, template, geometric, paint, home, triangle, geometric pattern, graphic, kid, child, square, bag, person, paper texture, window, creative, newspaper, plants',
'background, pattern, vintage, texture, paper, light, space, grunge, wall, note, flat, old paper, paper texture, desk, newspaper, recycle, natural, document, nature background, clean',
'background, pattern, vintage, texture, paper, light, space, grunge, wall, note, flat, old paper, paper texture, desk, newspaper, recycle, natural, document, nature background, clean',
'designer, table, workspace, computer, flat, object, workstation, desktop, design, work, office, home, desk, display, lamp, concept, cup, decor, modern, illustration, monitor, interior, inside, house, education, job, book, coffee, business, light, style, background, graphic, workplace, icons, symbol, elements, equipment, emblem, lifestyle, place, decorative, collection, room, set, organization, stylish, freelance, notepad, creative, jobs, creativity, mug, email, view, bulb, tablet, notebook, top, wood, number, texture, newspaper, think, paper, talk, bubble, mock-up, speech, item, media, template, idea, management, mock, project, mail, infographic, connect, wooden, chat, icon, content, pc, space, minimalism, vector, technology, web, screen, website, white, corporate, decorated, mouse, internet, process, clock',
'background, pattern, vintage, texture, paper, light, space, grunge, wall, note, flat, old paper, paper texture, desk, newspaper, recycle, natural, document, nature background, clean',
'pattern, vintage, texture, paper, light, space, grunge, wall, note, flat, old paper, paper texture, desk, newspaper, vintage pattern, recycle, natural, document, clean, floor',
'newspaper, texture, collage, news, old, background, text, book',
'newspaper, texture, space for copy, space, cover, white, textured, antique, text, press, write, worn, backdrop, surface, old, scratch, brown, ancient, light, background, vintage, effect, letter, space for text, template, blank, rough, color, line, book, pattern, stain, paper, design, copy, dirty, grunge, copyspace, aged, retro, banner, abstract, message, print, smudge, material, grungy, wooden, wall'];
$i = 0;
foreach ($titles as $title){
$entity = $datastore->entity('Examples');
$entity['title'] = $title;
$entity['tags'] = explode(", ", $tags[$i]);
$datastore->insert($entity);
$i = $i + 1;
}
sleep(1);
$query = $datastore
->query()
->kind('Examples')
->filter('tags','=','texture')
->filter('tags','=','newspaper');
$results = $datastore->runQuery($query);
$count = 0;
foreach ($results as $res) {
$count++;
}
echo 'Query by kind retrieves ', $count, ' results', PHP_EOL ;
$query = $datastore
->gqlQuery
("SELECT *
FROM Examples
where tags='texture' and tags='newspaper'",
['allowLiterals' => true]
);
$results = $datastore->runQuery($query);
$count = 0;
foreach ($results as $res) {
$count++;
}
echo 'Query by GQL retrieves ' ,$count, ' results', PHP_EOL;

Related

Why are the transparent pixels not blending correctly in WebGL

Result of my code:
Basically, what the issue is, the transparent part of my image are not blending correctly with what is drawn before it. I know I can do a
if(alpha<=0){discard;}
in the fragment shader, the only issue is I plan on having a ton of fragments and don't want the if statement for each fragment on mobile devices.
Here is my code related to alpha, and depth testing:
var gl = canvas.getContext("webgl2",
{
antialias : false,
alpha : false,
premultipliedAlpha: false,
}
);
gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.GREATER);
Also, these are textured gl.POINTS I am drawing. If I change the order the two images are drawn in the buffer, the problem doesn't exist. They will be dynamically rotating during the program's runtime so this is not an option.
It's not clear what your issue is without more code but it looks like a depth test issue.
Assuming I understand correctly you're drawing 2 rectangles? If you draw the red one before the blue one then depending on how you have the depth test setup the blue one will fail the depth test when the X area is drawn.
You generally solve this by sorting what you draw, making sure to draw things further away first.
For a grid of "tiles" you can generally sort by walking the grid itself in the correct direction instead of "sorting"
On the other hand, if all of your transparency is 100% draw or not draw then discard has its advantages and you can draw front to back. The reason is because in that case drawing front to back, the pixel drawn (not discarded) by the red quad will be rejected when drawing the blue quad by the depth test. The depth test is usually optimized to happen before running the fragment shader for a certain pixel. If the depth test says the pixel will not be drawn then no reason to even run the fragment shader for that pixel, time saved. Unfortunately as soon as you have any transparency that is not 100% opaque or 100% transparent then you need to sort and draw back to front. Some of these issues are covered in this article
A few notes:
you mentioned mobile devices and you mentioned WebGL2 in your code sample. There is no WebGL2 on iOS
you said you're drawing with POINTS. The spec says only POINTS of 1 pixel in size are required. It looks like you're safe up to points of size 60 but to be safe it's generally best to draw with triangles as there are other isses with points
you might also be interested in sprites with depth

Find same sequence of words in two strings

Before I start, I've searched for a long time trying to find a solution!
I'm trying to create a function that will return the longest matching sequence of words within 2 strings of different lengths.
from difflib import SequenceMatcher
file_1 = 'i took a walk around the world to ease my troubled mind i left my body lying somewhere in the sands of time i watched the world float to the dark side of the moon i feel there is nothing i can do yeah i watched the world float to the dark side of the moon after all i knew it had to be something to do with you i really dont mind what happens now and then as long as youll be my friend at the end if i go crazy then will you still call me superman if im alive and well will you be there holding my hand ill keep you by my side with my superhuman might kryptonite'
file_3 = 'when i was young i took a walk around the woods i found that i was both taller and smaller than the trees returning to my home i set out for the desert i journeyed for long days and nights my spirit left my body and i left my body lying somewhere in the sands of time unburdened by physical form i watched the world float away from me and into the vast moonlight'
match = SequenceMatcher(None, file_1, file_3).find_longest_match(0, len(file_1), 0, len(file_3))
print(file_1[match.a: match.a + match.size])
This currently prints out "i took a walk around the wo"
What it should print is "i left my body lying somewhere in the sands of time"
The alternative solution I've found is as below:
def longestSubstringFinder(string1, string2):
answer = ""
len1, len2 = len(string1), len(string2)
for i in range(len1):
for j in range(len2):
lcs_temp=0
match=''
while ((i+lcs_temp < len1) and (j+lcs_temp<len2) and string1[i+lcs_temp] == string2[j+lcs_temp]):
match += string2[j+lcs_temp]
lcs_temp+=1
if (len(match) > len(answer)):
answer = match
return answer
However, this also doesn't return what I want, as it prints "nd i left my body lying somewhere in the sands of time".
Any help would be greatly appreciated.

How can I find the minimum printer margins?

Problems:
I am printing custom size scenes, the printing must work on a variety of printers, standard or with custom sizes, or roll-fed (particularly this). Some of the custom printers are edge-to-edge.
The user-defined canvas may or may not match the printer paper size.... If the image is smaller than the paper, some printers will center it, others (like HP) print it on top left.
On some printers I can set "Custom" paper, others do not support it.
If the printer has minimum margins, some printers seem to clip, others to render from the top-left margin, and ma or may not clip on image size.
I would like to handle the clipping and margins myself and send to the printer the image as it should fit on "page".
m_printer->setPaperSize(QPrinter::Custom); //gives
QPrinter::setPaperSize: Illegal paper size 30
Assuming that the following works,
m_printer->setPaperSize(canvasRectangle.size(), QPrinter::Point);
getting the marked paper size in cups still returns the default marked in the ppd (Letter, w4h4, ...) (though I can print or cut that size)
What I need:
I need to find, for the (selected/custom) paper/page, the minimum margins.
I thought I could get the margins by just asking for them
qreal left, right, top, bottom;
m_printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Point);
qDebug() << left << right << top << bottom;
But regardless of printer (I tried HP, PDF and a custom edge-to-edge printer) I got 10 10 10 10.
I thought I would set them to 0 first... I got back 0. (but printing still used some tiny margins, which it either clipped or moved over depending on device, except for the edge-to-edge printers - so while I got no error setting margins to 0 when 0 is impossible, QPrinter told me it set margin to 0 successfully.)
Right now I am trying to make this work in Linux, using cups (and Qt 4.8) - I looked in the ppd of the various printers, but what I see, as ImageableArea for different provided sizes, is that each size has different margins - so that defies the minimum margins idea.
I imagined that the minimum margins (for maximum printable area) should not depend on the paper chosen, but on the printer geometry.
I considered getting the cups ppd option values for ImageableArea - but getting it for the "default" paper size doesn't seem useful if I am not using that paper size - and for custom paper size, there is a range so I don't know what I can get from it.
Also - I can't even seem able to get the cups option for ImageableArea:
const cups_dest_t* pDest = &m_pPrinters[iPrinterNumber];
for (int i = 0; i < pDest->num_options; ++i)
if (strcmp(pDest->options[i].name, pName) == 0)
// I can show options like "PageSize", "PageRegion" but not "ImageableArea"
I am struggling to understand this...
How can I find, using either Qt or cups, the minimum possible printer margins ?

Raster Scan in CRT display

In raster scan when the beam reaches the right-hand side of the screen it undergoes a process known as horizontal flyback, in which its intensity is reduced and it is caused to "fly back" across the screen (the top-most mauve line). While the beam is flying back, it is also pulled a little way down the screen.
Because of the inductive inertia of the magnetic coils which deflect the electron beam, there is a delay named horizontal/vertical retrace time.
Why the beam does not scan even lines from right to left (like below image)?
Horizontal retrace(flyback) time can reduced. There is no need to deflect beam horizontally at end of each line. just a tiny vertical deflect needed.
The one-way scan principle directly mirrors the way magnetics in deflection circuitry work: first there is slow current ramp along with ray moving left-to-right while the deflection/flyback transformer is connected to the constant voltage supply, then "flyback" stage with higher, opposite-polarity voltage applied to the deflection coil, made by disconnecting flyback deflection transformer from constant voltage supply.
Both-ways deflection would need push-pull configuration of deflection drivers, and that probably was considered too complicated and too costly during the early days of TV standards emerging.
Another reason could be the fact that there would be problematic to match the position of picture on neighbouring scanlines -- unlike the single-way deflection circuitry, that goes exactly the same every scanline.
To expand on lvd's comment about matching neighbouring lines, the diagrams you have are a simplification; on a real classic CRT nothing is horizontal. A real complete field looks more like:
There's no coupling between horizontal and vertical motion. Each acts entirely independently. Left-to-right deflection is doing one thing while top-to-bottom does another. There is no communication between the two. Don't think of it like a line printer.
The image formed on the screen is solid because each scan has a certain height to it. So the rows join up. If left-to-right scanning were left-to-right-to-left-to-right as proposed then either:
* the image wouldn't be solid. It'd be a zig zag of alternating diagonal lines that touched at the edges. Perceptually, it'd appear to be a lot darker in the middle; or
* the image would be very heavily overdrawn. Still darker in the middle, and also indistinct at the edges.
I drew this myself, so be forgiving; the degree of diagonal slant is identical between the three options:

standardize text using phonetic

i received data from a datacenter and i have to cleanse and make data useful and my biggest problem is one column lets call it "service_description" and for example the data center belong to a hair salon, this column is filled manually (text box) and contain huge amount of data (Billions), here is a small sample
service description
washed the haair
hair washed and dried
used shampoo on har
nails manicure
nail paint
nail pant
paint the nails
what i need to do is get each category together by ruining a script that will analyze each line and give it specif category e.g. hair could be the category for the first three lines because it is repeated in all of them while nail is category for the rest, taking in consideration the category word could be misspelled.
results
service description possible categories
washed the haair hair
hair washed and dried hair
used shampoo on har hair
nails manicure nail
nail paint nail
nail pant nail
paint the nails nail
I'm assuming your categories are fixed lookup.
I would split the string by white spaces; and for each part I would go through all items in your categories lookup, and pick the one with minimum levenshtein distance.
Some references:
http://en.wikipedia.org/wiki/Levenshtein_distance
http://www.codeproject.com/Articles/13525/Fast-memory-efficient-Levenshtein-algorithm

Resources