2016-12-21 107 views
0

我試圖從http://www.msmarco.org/dataset.aspx下載數據集。很高興看到數據集是以JSON格式。現在這甚至是JSON?

,如果打開dev的數據集,你可以看到,它的構成要素是這樣的:

{"passages": [{"is_selected": 1, "url": "http://www.indeed.com/cmp/Walgreens/salaries", "passage_text": "The average Walgreens salary ranges from approximately $15,000 per year for Customer Service Associate/Cashier to $179,900 per year for District Manager. Average Walgreens hourly pay ranges from approximately $7.35 per hour for Laboratory Technician to $68.90 per hour for Pharmacy Manager. Salary information comes from 7,810 data points collected directly from employees, users, and jobs on Indeed."}, {"is_selected": 0, "url": "http://www.answers.com/Q/What_is_the_average_gross_sales_volume_of_a_single_Walgreen's_Store", "passage_text": "The average revenue in 2011 of a Starbuck Store was $1,078,000, up from $1,011,000 in 2010. The average ticket (total purchase) at domestic Starbuck stores in No … vember 2007 was reported at $6.36. In 2008, the average ticket was flat (0.0% change)."}, {"is_selected": 0, "url": "http://news.walgreens.com/fact-sheets/frequently-asked-questions.htm", "passage_text": "In fiscal 2014, Walgreens opened a total of 184 new locations and acquired 84 locations, for a net decrease of 273 after relocations and closings. How big are your stores? The average size for a typical Walgreens is about 14,500 square feet and the sales floor averages about 11,000 square feet. How do we select locations for new stores? There are several factors that Walgreens takes into account, such as major intersections, traffic patterns, demographics and locations near hospitals."}, {"is_selected": 0, "url": "http://www.babson.edu/executive-education/thought-leadership/retailing/Documents/walgreens-strategic-evolution.pdf", "passage_text": "th store in 1984, reaching $4 billion in sales in 1987, and $5 billion two years later. Walgreens ended the 1980s with 1,484 stores, $5.3 billion in revenues and $154 million in profits. However, profit margins remained just below 3 percent of sales, and returns on assets of less than 10 percent."}, {"is_selected": 0, "url": "http://www.trefis.com/stock/wag/articles/199532/key-trends-driving-walgreens-business/2013-08-07", "passage_text": "The number of Walgreen stores has risen from 5,000 in 2005 to more than 8,000 at present. The average square footage per store stood at approximately 10,200 and we forecast the figure to remain constant over our review period. Walgreen earned $303 as average front-end revenue per store square foot in 2012."}, {"is_selected": 0, "url": "http://www.walgreens.com/storelocator/find.jsp?requestType=locator", "passage_text": "Your Walgreens Store. Select a store from the search results to make it Your Walgreens Store and save time getting what you need. Your Walgreens Store will be the default location for picking up prescriptions, photos, in store orders and finding deals in the Weekly Ad."}], "query_id": 9652, "answers": ["Approximately $15,000 per year."], "query_type": "numeric", "query": "walgreens store sales average"} 
{"passages": [{"is_selected": 0, "url": "http://www.breakintobartending.com/how-much-do-bartenders-make/", "passage_text": "A bartender’s income is comprised mostly of tips– 55% to be exact. In some states, employers aren’t even required to pay their bartenders the minimum wage and can pay as low as $2.13 per hour, and they depend on their tips almost entirely. Bartending can be a lot of things. For some it is exciting, for others exhausting. At times there is a lot of fun to be had, at others it is rather dull. But for the most part, bartending is almost always rewarding in the financial sense, as long as you stick with it."}, {"is_selected": 1, "url": "http://www.breakintobartending.com/how-much-do-bartenders-make/", "passage_text": "According to the Bureau of Labor Statistics, the average hourly wage for a bartender is $10.36, and the average yearly take-home is $21,550. Bartending can be a lot of things. For some it is exciting, for others exhausting. At times there is a lot of fun to be had, at others it is rather dull. But for the most part, bartending is almost always rewarding in the financial sense, as long as you stick with it."}, {"is_selected": 0, "url": "http://careerswiki.com/how-much-do-bartenders-make/", "passage_text": "About 551,100 individuals are employed as bartenders, with half of this number working part-time. The average annual salary for bartenders is $19,050 or an equivalent of $9.16 per hour, including tips. No formal training is needed for one to get a job as a bartender as all it takes are good customer service skills and a comprehensive knowledge about beverages and recipes. "}, {"is_selected": 0, "url": "http://www.answers.com/Q/How_much_do_bartenders_in_Las_Vegas_make", "passage_text": "Confidence votes 11. Bartenders in Vegas can make up to $7-$15 wage plus $10-$50 in tips per hour. But that totally depends on personality, gender and outlet. A hot young female can make $1000 a day tending bar in a strip club, but that is very exceptional. A bartender makes as much as a bartender wants to make. I wouldn't say there is a cap on how much a bartender make in one year. If the service is good and the coversation is i … nteresting a bartender can make alot of money. Location is also a big factor."}, {"is_selected": 0, "url": "https://answers.yahoo.com/question/index?qid=20100102233548AAZEutT", "passage_text": "Best Answer: An average bartender makes about...2 to 3 dollars an hour. but all the money is made off tips depending on the popularity of the bar. I used to make $700 to $1000 a night. but that is in Atlanta. If the bar is busy and you are a good bartender you will make quite a bit. I dont know how much, because I live in a town with a population of 2000 so there is not alot going on around here. Im sure the bartenders make a hundred to two hundred a night total (on a good night)...just depends."}, {"is_selected": 0, "url": "https://answers.yahoo.com/question/index?qid=20100102233548AAZEutT", "passage_text": "Report Abuse. no way to tell you how much bartenders make. in wages anything from minimum to $15 an hour. tips, anywhere from $20 to $300 or more a night. depends on a lot of things. those top dollar jobs only come after a lot of experience. If the bar is busy and you are a good bartender you will make quite a bit. I dont know how much, because I live in a town with a population of 2000 so there is not alot going on around here. Im sure the bartenders make a hundred to two hundred a night total (on a good night)...just depends."}, {"is_selected": 0, "url": "http://work.chron.com/much-bartender-make-annually-7503.html", "passage_text": "Pay by Employment Setting. Bartenders who worked in hotels and hotel restaurants generally reported the highest incomes in 2011, an average of $26,180 a year. Bartenders employed in full-service restaurants tended to earn somewhat less, averaging about $22,130 a year. Bartenders employed by bars earned an average of $20,230 per year, and bartenders who worked for civic and social organizations earned an average of $18,970 a year. The median earnings of bartenders during this period were $9.06 an hour and $18,850 a year. Eighty percent of bartenders in the U.S. reported annual incomes of between $16,170 and $31,860."}, {"is_selected": 0, "url": "http://www.celebritynetworth.com/articles/how-much-does/how-much-does-bartender-make/", "passage_text": "Tips make up half or more of bartender's salaries. If a bartender earned $6.00 an hour, their tips generally average out to $12.00 to $18.00 an hour as additional income. A bartender in an average bar will typically earn $15.00 $30.00 an hour between their wages and tips. According to bartending.org, bartenders in a high volume resort or establishment can earn $50,000 to $75,000 per year between hourly wages and tips. Indeed.com 2010 results show bartenders in restaurants at median salary rates can make a good salary per year: Bartender $73,000."}], "query_id": 9653, "answers": ["$21,550 per year", "The average hourly wage for a bartender is $10.36 and the average yearly take-home is $21,550."], "query_type": "numeric", "query": "how much do bartenders make"} 

現在,這些塊重複沒有任何封閉的{}沒有逗號分隔它們。顯然這不能是JSON。

我的問題是:

  1. 這真的是JSON作爲數據集聲稱是?

  2. 任何庫(最好在python中)解析它以提取所有單個字段。

我試過ijson在python中,但這真的看起來不像真正的json。

+0

Jep ..即JSON。嘗試https://jsonformatter.curiousconcept.com/ – putvande

+0

是的,它的有效JSON。在這裏試試http://jsonlint.com/ – Arjit

+0

不,你錯了。這是數據集的一個元素。正如我所說,重複沒有任何括號括號。 – Rafael

回答

3

該文件由每行一個JSON文檔組成:這是JSON Lines

該文件作爲一個整體不是有效的JSON文檔。你應該讀行線並互相喂線成JSON解析器:

#!/usr/bin/env python3 
from sys import argv 
import json 

with open(argv[1], "r", encoding="UTF-8") as f: 
    lines = [ json.loads(line) for line in f ] 

注:另一個類似的格式是JSON-SEQ在RFC7464記錄。

+0

@ T.J.Crowder:它們表示可以使用只有ASCII字符的JSON編碼任何unicode字符串。這並不意味着你只需要使用ASCII字符。 – ysdx

+0

@ysdx:我明白你在說什麼了,謝謝。我個人認爲,要求JSON行是UTF-8是錯誤的(它可以輕鬆地在特定文本中翻倍或甚至增加文件大小),但是,嘿,我沒有提出JSON行,所以... :-) –

+0

@ysdx非常感謝您的幫助。我使用逐行解析工作。 – Rafael