I have a dataset containing names in both English and other languages and mixed too. Is their any way to remove data containing other than English language?
Eg:
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI have a dataset containing names in both English and other languages and mixed too. Is their any way to remove data containing other than English language?
Eg:
You can use regular expressions. I dont know how to in Field Calculator so I use Python.
This doesnt identify language, just the characters a-Z.
See Extracting only characters from a string in Python
import re
#Change these three lines to match your layer and field names
layer = QgsProject.instance().mapLayersByName("plingplong")[0]
field_to_read = "fielda"
field_to_update = "Required N"
fieldindex = layer.fields().indexFromName(field_to_update) #Find the index of the field to update
new_attributes = {}
pattern = r"(?i)\b[a-z]+\b"
for feature in layer.getFeatures():
words = ' '.join(re.findall(pattern, feature[field_to_read]))
#print(words)
#hello
#this is a text
new_attributes[feature.id()]={fieldindex:words}
#new_attributes is now, each features id: {index of field to update: new text}
#{0: {1: 'hello'}, 1: {1: 'this is a text'}}
layer.dataProvider().changeAttributeValues(new_attributes)
"plingplong"
to the name of your layer? That error usually occur when it cant find the layer by the layer name your searching for
Use regular expressions with Field Calculator. Based on regular expressions \\p{Latin}
(to match all latin characters) and \\s
(to match whitespaces), use regex_replace()
function to delete everything else (see here for details):
regexp_replace ("Actual Name",'([^\\p{Latin}|\\s])','')
This expression keeps latin characters and white spaces from the input and deletes everything else.
Paris
can stand for the capital of France and than can be cosidered to be "french", but Paris
is also the name of different towns in the US (like in Idaho), Canada (Ontario), Denmark etc., see en.wikipedia.org/wiki/Paris_(disambiguation) and in these cases, the placename can be considered to be english, danish etc. So really impossible to recognize "languages". How should anyone being able to recognize the language of placenames like Arel
?