LIWC2015分析的驱动因素。不包括LIWC2015字典。

liwc-analysis的Python项目详细描述


LIWC分析

此包用作liwc2015.txt字典的驱动程序。字典不包括在内,可以直接从LIWC购买。

用法

用法相当直截了当。首先导入包

importliwcanalysis

然后需要创建一个liwc分析的实例,该实例的路径是.txt文件。

LIWCLocation="/Users/Eric/repositories/transcript-analysis/LIWC/LIWC.2015.all.txt"LIWC=liwcanalysis.liwc(LIWCLocation)

然后,您可以传入要分析的字符串列表,以接收结果字典和计数字典的元组。

transcripts={"Example1":"This is a single transcript. Red hat angry.","Example2":"This is another single transcript. Dog boy cat.",}str_list=[]forkeyintranscripts:str_list.append(transcripts[key])result_dics,count_dics=LIWC.analyze(str_list)

请注意,analyze()可以接受单个字符串参数或字符串列表。示例:

# this is validresult_dics,coutn_dics=LIWC.analyze(["this is a string","here is another","one more"])# this is also validresult_dics,coutn_dics=LIWC.analyze("this is a string")

result_dics是字典列表。每个字典对应于传入analyze的一个字符串。每本词典都遵循"LIWC Category": [list, of, words, matched]的形式。例如,一个字符串的字典可能类似于:

{
    "FUNCTION": ["is", "a"],
    "QUANT": ["single"],
    ...
}

count_dicsresult_dics非常相似,但它不是给出匹配的单词列表,而是给出每个匹配单词列表的长度:

{
    "FUNCTION": 2,
    "QUANT": 1,
    ...
}

最后,您可以使用:

LIWC.print(output_dir,titles)

您需要指定输出目录,以及每个字符串的标题列表。有关更多详细信息,请参见完整示例。

还可以使用LIWC.get_categories()检索按字母顺序排序的LIWC类别列表(a->;z)。

完整示例

importliwcanalysistranscripts={"Example1":"This is a single transcript. Red hat angry.","Example2":"This is another single transcript. Dog boy cat.",}str_list=[]forkeyintranscripts:strs.append(transcripts[key])LIWCLocation="/Users/Downloads/LIWC/LIWC.2015.all.txt"output_dir="/Path/to/my/file/"LIWC=liwcanalysis.liwc(LIWCLocation)result_dics,count_dics=LIWC.analyze(str_list)LIWC.print(output_dir,list(transcript.keys()))

使用print将返回以下表格: /路径/to/my/file/liwccounts.csv:

CategoryExample1Example2
ADJ11
ARTICLE1
AUXVERB11
FOCUSPRESENT11
FUNCTION22
IPRON1
MALE1
NUMBER11
PRONOUN1
QUANT12
SOCIAL1
VERB11
WORK11
TOTAL88

/路径/to/my/file/liwcwords.csv:

CategoryExample1Example2
ADJ['single']['single']
ARTICLE['a']
AUXVERB['is']['is']
FOCUSPRESENT['is']['is']
FUNCTION['is', 'a']['is', 'another']
IPRON['another']
MALE['boy']
NUMBER['single']['single']
PRONOUN['another']
QUANT['single']['another', 'single']
SOCIAL['boy']
VERB['is']['is']
WORK['transcript.']['transcript.']

/路径/to/my/file/liwcrelativerefreq.csv

CategoryExample1Example2
ADJ0.1250.125
ARTICLE0.125
AUXVERB0.1250.125
FOCUSPRESENT0.1250.125
FUNCTION0.250.25
IPRON0.125
MALE0.125
NUMBER0.1250.125
PRONOUN0.125
QUANT0.1250.25
SOCIAL0.125
VERB0.1250.125
WORK0.1250.125

如果您有任何问题或功能要求,请告诉我。请随时打开一个请求,发布,或向我发送一封电子邮件到ericwiener3@gmail.com

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用McClickListener单击了什么元素   Java时间戳在Oracle时间戳中不同情况下存储12 PM的奇怪行为   java无法使用事件总线对运行在不同机器上的垂直体进行通信   java Mockserver:收到请求后进行回调   java无法将Json字符串转换为Map<string,Object>   java如何按升序排列输出?   java视图行,带有oracle键。jbo。在SrCategoryParentIterator中找不到键[300100120394155]   javafxmysql连接示例   java正在等待加载完成   java是否可以将同一个有状态会话bean实例注入多个其他会话bean?   java无法让万向节检测离开或进入区域   使用JavaCV和OpenCV的java提供了dyld:lazy符号绑定失败:找不到符号:__sincos_stret   xml解析无法使用Java读取xml文档   java无法更改工具栏的颜色   javaapachesshd和JSCH   java无法在firebase存储中检索图像url   java问题与executeUpdate   同一应用程序中不同活动之间的java SharedReference