how to query watson discovery api? - ibm-watson

I am experimenting IBM watsons' Discovery API to get data insights. I want to query using multiple filters. I am using python to accomplish the task. I have tried this for now, but this is not working.
qopts = {'filter':[{'enriched_text.entities.text:Recurrent Neural
Networks,Machine Learning classifiers'}]}
my_query = discovery.query(env_id, coll_id, qopts)
with only single entity : 'recurrent Neural Networks' through the discovery UI and through my python query, I get 3 documents from the collection.
but with two entities, 'Recurrent Neural Networks,Machine Learning classifiers', in the UI I get 2 documents but through my code, I get 2 documents.

Below is then right format which works for me. with multiple concept and keyword filters, I get a total of 2 search results, which match with the UI query
qopts = {'filter':{'enriched_text.concepts.text:"Neural network",enriched_text.keywords.text:"Neural Network",enriched_text.keywords.text:"generative conversational models"'}}
with only entity I get 3 match results
qopts = {'filter':{'enriched_text.concepts.text:"Neural network"'}}
in this example I am querying the documents with concept 'Neural network' , keywords 'Neural Network' and 'generative conversational models'

Inside Watson discovery documentation, inside the UI you'll use (according to the documentation):
But obviously, without the ! operator inside the second text.
and I think inside your code you need to use , between the values.
Not sure because I don't use the enriched_text.entities.textinside my filter, just the Strings.
One possible reference for another example to test:
filter=field1:some value,field2:another value
Official reference documentation: here.

Related

Can i merge/combine graphql API arrays into one?

Hey i'm using Sanity and have created both a allSanityPost (for my blog posts) and allSanityCases (for all my cases). Do anyone know how to combine these categories into one array and order them by their "published-date"? I want to display them both on one blog page - but not in separated lists.
I'm building the page with Gatsby, so react answers would be preferable :)
Cheers
The current GraphQL endpoint have no way of querying across documents like GROQ does. Therefore, you will have to do this after querying the GraphQL endpoint for data. I suggest querying for both all posts and all cases separately like this:
query {
allSanityPost{
title
},
allSanityCases{
title
}
}
Given that both of these types have some sort of date, you should be able to combine them into one single array, and then do your sorting thereafter.

Implementing guided navigation using vespa

I'm trying to implement guided navigation using vespa. At present, I am using grouping to implement it. I've written a query like this.
SELECT * FROM entity where sddocname contains 'entity' | all(group(category) each(group(item_category) each(output(count()))));
In the above example category is like "electronics","automobiles" etc and "item_category" is like "mobile phone","car"etc.
I don't want to select any documents, I just wanted to see the grouped data. Is there a better way to solve this problem?
Use limit 0 to remove the plain hit list. Example here https://docs.vespa.ai/documentation/tutorials/blog-search.html
limit 0 in yql or just specify &hits=0

SuiteCommerce Advanced - Show a custom record on the PDP

I am looking to create a feature whereby a User can download any available documents related to the item from a tab on the PDP.
So far I have created a custom record called Documentation (customrecord_documentation) containing the following fields:
Related item : custrecord_documentation_related_item
Type : custrecord_documentation_type
Document : custrecord_documentation_document
Description : custrecord_documentation_description
Related Item ID : custrecord_documentation_related_item_id
The functionality works fine on the backend of NetSuite where I can assign documents to an Inventory item. The stumbling block is trying to fetch the data to the front end of the SCA webstore.
Any help on the above would be much appreciated.
I've come at this a number of ways.
One way is to create a Suitelet that returns JSON of the document names and urls. The urls can be the real Netsuite urls or they can be the urls of your suitelet where you set up the suitelet to return the doc when accessed with action=doc&id=_docid_ query params.
Add a target <div id="relatedDocs"></div> to the item_details.tpl
In your ItemDetailsView's init_Plugins add
$.getJSON('app/site/hosting/scriptlet.nl...?action=availabledoc').
then(function(data){
var asHtml = format(data); //however you like
$("#relatedDocs").html(asHtml);
});
You can also go the whole module route. If you created a third party module DocsView then you would add DocsView as a child view to ItemDetailsView.
That's a little more involved so try the option above first to see if it fits your needs. The nice thing is you can just about ignore Backbone with this approach. You can make this a little more portable by using a service.ss instead of the suitelet. You can create your own ssp app for the function so you don't have to deal with SCAs url structure.
It's been a while, but you should be able to access the JSON data from within the related Backbone View class. From there, within the return context, output the value you're wanting to the PDP. Hopefully you're extending the original class and not overwriting / altering the core code :P.
The model associated with the PDP should hold all the JSON data you're looking for. Model.get('...') sort of syntax.
I'd recommend against Suitelets for this, as that's extra execution time, and is a bit slower.
I'm sure you know, but you need to set the documents to be available as public as well.
Hope this helps, thanks.

Watson RnR - Creating Ranker using REST API

I am trying out to create an Ranker using the REST API after successfully Adding documents to the collection.
Do I need to use train.py. If so then whats the use of create Ranker API. Also while trying to create RANKER, can you please tell me where do I need to specify cluster id and collection name. Do I need to specify it in metadata.json file.
Any help would be highly appreciated.
See here for an overview of the methods available for training a ranker: https://www.ibm.com/watson/developercloud/doc/retrieve-rank/training_data.html#methods. Using the REST API directly is described under the 'Manually training a ranker' section and is intended for advanced users that might be appending additional columns to the feature vectors that are generated automatically when you use train.py.
The create Ranker REST API call does not take 'cluster id' and 'collection names' as input parameters. It assumes that you've already used the /fcselect REST API call (which does take 'cluster id' and 'collection id') to pre-generate feature vectors similar to what train.py is doing internally. Again, in the advanced use case, you might take these feature vectors and then augment them using some other custom features as described in this blog post: https://medium.com/machine-learning-with-ibm-watson/developing-with-ibm-watson-retrieve-and-rank-part-3-custom-features-826fe88a5c63#.unfm2ocik

obtain demographic data with google analytics api

im trying to obtain some demographic data from the google analytics api, my intention is to integrate this on a cms to generate reports, etc... is this possible?
if it is, is there someone who knows a tutorial or something? i have used the examples provided and i get some sessions that have been in the last 7 day period. But nothing besides that. If that is not possible, what kind of things i can obtain with this api?
here is what i have tried:
function getResults(&$analytics, $profileId) {
return $analytics->data_ga->get(
'ga:' . $profileId,
'7daysAgo',
'today',
'ga:sessions');
}
thanks in advance.
You can obtain everything that's listed in the Dimensions and Metrics Reference. This includes ga:userAgeBracket and ga:userGender for demographic information.
To include additional metrics (numerical data) you put it as a parameter where you now have ga:sessions (separate multiple metrics with a comma). You need at least one metric for a query to work.
To add dimensions (i.e. categorical data) you need to pass an options array to your query that has a key/value pair for dimensions. This may also include additional options like filters or sort options, see the example here..
$optParams = array(
'dimensions' => 'ga:userAgeBracket,ga:userGender'
);
return $analytics->data_ga->get(
'ga:' . $profileId,
'7daysAgo',
'today',
'ga:sessions',
$optParams
);
This for version 3 of the API. If you are just getting started an have no legacy code to maintain you might as well start with there current version (v4).
To be able to get age and gender informations from analytics, you should Enable Demographics and Interests reports on your GA account.
doc : https://support.google.com/analytics/answer/2819948

Resources