#############################################################################
## 本脚本对以tab格式存储的字符进行频率统计（ASJP模式的字符模式）。 ##
## 运行本脚本时需手动以表格方式调入或选中需要统计的表格。结果也需手动存储。##
## Written by Qibin Ran (ranqibin@126.com).                                ##
## 2019-09-14                                                              ##
#############################################################################

Create Table with column names... result 0 symbol times

pause 调入或选中需要进行音标频率统计的表格
tableName$ = selected$("Table",1)

# 求需要统计的表格中有多少行
nOfR = Get number of rows
# 求需要统计的表格中有多少列
nOfC = Get number of columns

# 循环列
for icolumn to nOfC
	select Table 'tableName$'
	columnLabe$ = Get column label... 'icolumn'

	# 循环行
	for irow to nOfR
		select Table 'tableName$'
		# 求每一行中单词的音标
		wordcontent$ = Get value... 'irow' 'columnLabe$'
		# 求该音标的长度
		ln = length(wordcontent$)

		# 循环该音标的长度
		for i to ln
			select Table result

			# 求某单词音标右边第i个音素
			r1$ = right$(wordcontent$,i)

			if i = 1
				select Table result
				# 设定在列中的搜索结果（search result）
				sr = Search column... symbol 'r1$'
				
				if sr = 0
					Append row
					nOfR2 = Get number of rows
					Set string value... nOfR2 symbol 'r1$'
					Set string value... nOfR2 times 1
				else
					# 求某音标原来的次数（original number）
					on = Get value... sr times
					# 设定新的次数（new number）
					nn = on + 1
					Set string value... sr times 'nn'
				endif
			endif
			if i > 1
				# 求应减去的右边的音标（rigth jian）
				x = i - 1
				rj$ = right$(wordcontent$,x)

				# 求右边的i个音素
				ri$ = right$(wordcontent$,i)

				# 求减去右边第i个音素后剩下的音标（right sheng）
				rs$ =  ri$ - rj$

				# 如果经过上面的步骤，求得的音素是非空格，则增加1个频数
				if rs$ = " " or rs$ = "/" or rs$ = "," or rs$ = "" or rs$ = ":" or rs$ = "，" or rs$ = "。"
				...or rs$ = "：" or rs$ = "“" or rs$ = "”" or rs$ = "《" or rs$ = "》" or rs$ = "、" or rs$ = "？"
				else
					select Table result
					# 设定在列中的搜索结果（search result）
					sr = Search column... symbol 'rs$'
				
					if sr = 0
						Append row
						nOfR2 = Get number of rows
						Set string value... nOfR2 symbol 'rs$'
						Set string value... nOfR2 times 1
					else
						# 求某音标原来的次数（original number）
						on = Get value... sr times
						# 设定新的次数（new number）
						nn = on + 1

						Set string value... sr times 'nn'
					endif
				endif
			endif 
		endfor
	endfor
endfor

# 选中结果表格，使其按音标频率从高往低排列
select Table result
Sort rows... times
Reflect rows

exit 所有字符已经提取并出具频率报告！
