使用OCR工具我从截图中提取文本(每个约1-5个句子).但是,在手动验证提取的文本时,我注意到有时会出现几个错误.
鉴于文本"你好!我真的喜欢Spark❤️!",我注意到:
1)像"I","!"和"l"这样的字母被"|"代替.
2)Emojis未被正确提取并被其他字符替换或被遗漏.
3)不时删除空格.
结果,我可能会得到一个像这样的字符串:"你好7l |真实|喜欢Spark!"
因为我试图将这些字符串与包含正确文本的数据集相匹配(在这种情况下"Hello there!我真的很喜欢Spark❤️!"),我正在寻找一种有效的方法来匹配Spark中的字符串.
任何人都可以建议一个有效的Spark算法,它允许我比较提取文本(〜100.000)与我的数据集(约1亿)?
我需要删除西班牙语中的重音和来自不同数据集的其他语言的重音.
我已经在这篇文章提供的代码中做了一个函数,删除了特殊的重音符号.问题是函数很慢,因为它使用了UDF.我只是想知道我是否可以提高函数的性能以在更短的时间内获得结果,因为这对小型数据帧有好处,但对大型数据帧则不行.
提前致谢.
在这里代码,您将能够按照它呈现的方式运行它:
# Importing sql types
from pyspark.sql.types import StringType, IntegerType, StructType, StructField
from pyspark.sql.functions import udf, col
import unicodedata
# Building a simple dataframe:
schema = StructType([StructField("city", StringType(), True),
StructField("country", StringType(), True),
StructField("population", IntegerType(), True)])
countries = ['Venezuela', 'US@A', 'Brazil', 'Spain']
cities = ['Maracaibó', 'New York', ' São Paulo ', '~Madrid']
population = [37800000,19795791,12341418,6489162]
# Dataframe:
df = sqlContext.createDataFrame(list(zip(cities, countries, population)), schema=schema)
df.show()
class Test():
def __init__(self, df):
self.df = df
def clearAccents(self, …Run Code Online (Sandbox Code Playgroud) python unicode-normalization apache-spark apache-spark-sql pyspark