大数据存储系统(3)--- Document Store

本文探讨大数据存储系统中的Document Store,重点分析Google Protocol Buffers,一种起源于网络协议表达的数据结构,并将其与JSON进行对比。同时,提到了MongoDB如何在SQL功能基础上提供简单易用的接口。
摘要由CSDN通过智能技术生成
Document Store
一、数据模型
1、 JSON:JavaScript Object Notation
JSON是一个低成本的数据交换格式;是JavaScript程序语言标准(1993年)的子集。JSON对应于程序语言中的结构与数组。
(1)JSON格式定义
Value:基础类型、Object、Array
Object:{“key1”:value1,……,”keyn”:valuen}
Array:[value1, ……, valuen]
JSON的数据类型定义是完全动态的,一个JSON记录本身自定义了自己的类型,不需要事先声明schema



2、Google Protocol Buffers

Google推出,最初用于实现网络协议,所以叫protocol buffers。可以用于表达程序设计语言中的结构和数组。要求先定义类型,然后才可以表达数据。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是Python实现英文大数据txt文本TF-IDF提取关键词的代码: ```python import os import math import string from collections import Counter # 读取文本文件 def read_file(filename): with open(filename, 'r', encoding='utf-8') as f: text = f.read() return text # 分词 def tokenize(text): words = text.lower().split() # 去除标点符号 words = [word.strip(string.punctuation) for word in words] # 去除数字和单个字母 words = [word for word in words if not any(c.isdigit() for c in word) and len(word) > 1] return words # 计算单词出现次数 def count_words(words): word_counts = Counter(words) return word_counts # 计算单词在文档中出现的频率 def compute_word_frequency(word_counts): total_count = sum(word_counts.values()) word_freqs = {word: count/total_count for word, count in word_counts.items()} return word_freqs # 计算单词在文档集合中出现的文档数量 def compute_document_frequency(word, documents): count = sum(1 for document in documents if word in document) return count # 计算单词的逆文档频率 def compute_inverse_document_frequency(word, documents): N = len(documents) df = compute_document_frequency(word, documents) idf = math.log(N/df) return idf # 计算TF-IDF def compute_tf_idf(word, words, documents): tf = words[word] idf = compute_inverse_document_frequency(word, documents) tf_idf = tf * idf return tf_idf # 提取关键词 def extract_keywords(filename, num_keywords=10): # 读取文本文件 text = read_file(filename) # 分词 words = tokenize(text) # 计算单词出现次数 word_counts = count_words(words) # 计算单词在文档中出现的频率 word_freqs = compute_word_frequency(word_counts) # 计算TF-IDF documents = [words] tf_idfs = {word: compute_tf_idf(word, word_freqs, documents) for word in word_counts.keys()} # 获取前num_keywords个TF-IDF最高的关键词 keywords = sorted(tf_idfs.items(), key=lambda x: x[1], reverse=True)[:num_keywords] return [keyword[0] for keyword in keywords] # 测试 filename = 'data.txt' keywords = extract_keywords(filename, num_keywords=10) print(keywords) ``` 其中,`read_file`函数用于读取文本文件,`tokenize`函数用于对文本进行分词,`count_words`函数用于统计单词出现次数,`compute_word_frequency`函数用于计算单词在文档中出现的频率,`compute_document_frequency`函数用于计算单词在文档集合中出现的文档数量,`compute_inverse_document_frequency`函数用于计算单词的逆文档频率,`compute_tf_idf`函数用于计算TF-IDF,`extract_keywords`函数用于提取关键词。 在测试时,将要提取关键词的文本文件路径传入`extract_keywords`函数,同时可以指定要提取的关键词数量。运行后,将会返回一个关键词列表,其中包含了TF-IDF值最高的前num_keywords个关键词。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值