regarding freebase library (how to use bol (film) title as id?) - python

I'm using freebase library to print the article. All is working fine. But I want to ask something from you. Following example working fine. Suppose I have title like this bol (film). Now I want to use this title like this "id": "/en/bol_(film)",. But This is not working. In wikipedia API, We can use this title as bol20%28%film29%. Can any one help me? thanks so much
query = [{
"id": "/en/barak_obama",
"/common/topic/article": [{
"id": None
}],
"/common/topic/image": [{
"id": None
}]
}]
EDIT : I have read this for freebase site. But This is not working.
For example, $0028 in a fully-qualified name represents a left parenthesis and $0029 represents a right parenthesis. (See Section 2.5.9 for the full list of legal characters in fully-qualified names.

There is no guarantee that there will be an id /en/foo for a given title "Foo". In order to find the correct id for your topic you have to either use the search service to get a list of candidate ids, or use MQL for exact phrase matches.
Search
https://www.googleapis.com/freebase/v1-sandbox/search?query=bol
or
http://tinyurl.com/3w9yvyz

Related

how can i get all the datas that have same value from mongodb?

in my database, there are two companies with same name.
[
{
"name": "samsung",
"store_code": "34d"
},
{
"name": "lg",
"store_code": "333"
},
{
"name": "lg",
"store_code": "3511"
}
]
like this..
my question is, I juse made my python function to get store information by name.
that looks like this..
async def fetch_store_by_name(store_name):
document = collection.find_one({"name":store_name})
return document
and I can only get the first lg company's information.
how can I get both informations of lg company from my mongodb?
Use find instead of find_one .
https://www.w3schools.com/python/python_mongodb_find.asp
I assumed you're using pymongo, just change find_one to find method. Like this:
async def fetch_store_by_name(store_name):
document = collection.find({"name":store_name})
return document
Here some documentation : https://pymongo.readthedocs.io/en/stable/tutorial.html#querying-for-more-than-one-document
You can use collection.find({"name":store_name})
Reference:
https://www.w3schools.com/python/python_mongodb_find.asp
Using variables such as name, address, zip code to identify a document is not a good approach as there may be the same names, names with different cases, spaces ex: LG, lg.
You can use the default mongo _id as a unique property to find the doc. Still you want to get the document then use collection.find({"name":store_name}) it will returns multiple documents ab array. If you want to retrieve only one doc then use collection.findOne({"name":store_name})

How to get the rows extracted if few columns are blank or empty

I am new to this and would need some help in extracting the records/row only when few columns are blank. Below code is ignoring the blank records and getting me the ones with value. Can someone suggest here ?
mongo_docs = mongo.db.user.find({"$and":[{"Param1": {"$ne":None}}, {"Param1": {"$ne": ""}}]})
The query you are using contains ne which stands for not-equal. You can change that to eq (equals) and check if you get the desired results.
mongo_docs = mongo.db.user.find({"$or":[{"Param1": {"$eq":None}}, {"Param1": {"$eq": ""}}]})
A simplification of the above code will also be:
mongo_docs = mongo.db.user.find({"$or":[{"Param1": {"$eq":None, "$eq": ""}}]})
You can also use the exists query if that better satisfies your requirement.
From the comments: You are absolutely right, the command will work with multiple parameters.
mongo_docs = mongo.db.user.find({"$or":[{"Param1": {"$eq":None, "$eq": ""}}, {"Param2": {"$eq":None, "$eq": ""}},{"Param3": {"$eq":None, "$eq": ""}}]})
Additionally, if you want to do it over a larger range, you can consider using text indexes. These will allow you to search all the test fields at once, and the code for the same should look something like this:
mongo.db.user.createIndex({Param1: "text", Param2: "text", Param3: "text"})
mongo.db.user.find({$text: {$search: ""}})
The above works for text content only, and I have not come across any implementation for integer values yet but cannot see why the same should not work with some minor changes using other wildcards.
References:
Search multiple fields for multiple values in MongoDB
https://docs.mongodb.com/manual/text-search/
https://docs.mongodb.com/manual/core/index-text/#std-label-text-index-compound
https://docs.mongodb.com/manual/core/index-wildcard/

Podio: How do I add a comment to an item I just created using the API for Python 3?

For Python 3 I can't seem to find a Comment-class anywhere in the API, like what is referred to in the documentation. I've tried a number of different ways that I can think of as guesses on how to add the comment using the Item.create- and Item.update-methods but nothing I've tried has worked. So, how would I do this?
Neither can I find anything called "commentable ID" or "commentable type". Are those simply the item-ID and item-type of the item I want to add the comment to?
As a newbie-programmer, the documentation is not really very easy to interpret.
Thanks in advance.
Could you refer to
https://developers.podio.com/doc/comments/add-comment-to-object-22340 , which is explaining adding comments to object.
Eg:
PodioComment::create( $ref_type, $ref_id, $attributes = array() );
ref_type may be App or Item
Ref_id id corresponding id such as app_id or itemid
and the parameters as
{
"value": The comment to be made,
"external_id": The external id of the comment, if any,
"file_ids": Temporary files that have been uploaded and should be attached to this comment,
[
{file_id},
.... (more file ids)
],
"embed_id": [OPTIONAL] The id of an embedded link that has been created with the Add an mebed operation in the Embed area,
"embed_url": The url to be attached
}
In response you get the comment_id. If you wanna edit the existing comment use the comment_id in request as described.

MongoDB PyMongo basic help - extracting info from a document

I think this is a fairly basic question, but I can't figure this part out. So, basically, in my code, I have isolated a document, like so:
document = collection.find_one(name)
And now that I have this document, I want to know how to print out a certain key for this specific document. So, basically, this document looks like this right now:
{
"_id" : ObjectID("...")
"name": ABCD
"info": {
"description" : "XYZ"
"type" : "QPR"
}}
And I want to know how I can extract and print "XYZ" using the variable "document" that has the entire document in it.
document is a regular Python dictionary:
print(document["info"]["description"])
This, as well as, a lot of relevant PyMongo basic usage information is covered in the PyMongo Tutorial - make sure to study it.
It is just a dictionary
print(document['info']['description'])
or if you are not sure if your document contains the right keys
info = document.get('info', None)
if info:
print(document.get('description', 'No description'))

OR condition in motor python

Hi I am experimenting with python and mongodb with tornado framework. I am having entry module where user can insert the data of students in academic and sports field. In mongodb terminal I did search with
db.student.find( { $or: [ { "academy": name }, { "sports": name } ] } )
but when I try to do the same with python along with MOTOR driver I end up with error.
My python command is
doc = yield db.student.find_one({ $or: [{"academy": name}, {"sports": name}]})
Can anyone guide me how I can do the search with or condition in python motor?
The or condition is used to check whether the data of particular student is entered in both the fields or not.
You write, "I end up with an error", but it is very difficult for anyone to answer your question if you don't tell us what the error is!
In this particular case I think I know the problem. In Python, all field names must be quoted. The proper syntax is:
doc = yield db.student.find_one({ "$or": [{"academy": name}, {"sports": name}]})

Categories