diff --git a/config/migrations/2023/20231112161533-update-phone-numbers.sparql b/config/migrations/2023/20231112161533-update-phone-numbers.sparql index 78d38ac..64b78ca 100644 --- a/config/migrations/2023/20231112161533-update-phone-numbers.sparql +++ b/config/migrations/2023/20231112161533-update-phone-numbers.sparql @@ -12,9 +12,8 @@ WHERE { GRAPH { ?s ?o . } - - FILTER (SUBSTR(?o, 1, 1) != "+" AND STRLEN(STR(?o)) > 4 and !regex(?o, ".*[a-zA-Z].*", "i")) BIND(REPLACE(STR(?o),"[. -/()]","") AS ?removedSpaces) . + FILTER (SUBSTR(?removedSpaces, 1, 1) != "+" AND STRLEN(STR(?removedSpaces)) > 8 AND STRLEN(STR(?removedSpaces)) < 11 and !regex(?o, ".*[a-zA-Z].*", "i")) BIND (CONCAT('tel:+32', SUBSTR(?removedSpaces, 2)) as ?newPhoneNumber) } @@ -34,9 +33,8 @@ WHERE { GRAPH { ?s ?o . } - - FILTER (STRSTARTS(?o, "+") and !regex(?o, ".*[a-zA-Z].*", "i")) BIND(REPLACE(STR(?o),"[. -/()]","") AS ?removedSpaces) . + FILTER (STRSTARTS(?o, "+") and !regex(?o, ".*[a-zA-Z].*", "i")) BIND (CONCAT('tel:+', ?removedSpaces) as ?newPhoneNumber) } diff --git a/config/reasoner/dl2op/main/phone_number.n3 b/config/reasoner/dl2op/main/phone_number.n3 new file mode 100644 index 0000000..db784d8 --- /dev/null +++ b/config/reasoner/dl2op/main/phone_number.n3 @@ -0,0 +1,46 @@ +PREFIX string: +PREFIX e: +PREFIX schema: +#:s :p +# "+32488888888", +# "0477777777", +# "0477.77.77.00", +# "0", +# " +32 445 55 99 91", +# "tel:+3144887755", +# "0032 4 58 44 66 87", +# "00 32 0 498 77 7744". +{ + + + ?s schema:telephone ?number. + + # number not matches regex + + ?number string:notMatches """[a-zA-Z]""". + + # Remove all non digits + ( ?number """[^+\\d]""" "" ) string:replace ?scrape_result. + + # Replace leading 00 with + + ( ?scrape_result """^00""" "+") string:replace ?replaced_zero_zero. + + ( ?replaced_zero_zero """^0""" "+32") string:replace ?default_be. + + ( ?default_be """\\+320""" "+32" ) string:replace ?result. + + # ?result string:matches """^+((32\\d{8})|(324\\d{8})|((?!32)\\d+))$""". + ?result string:matches """^\\+((32\\d{8})|(324\\d{8})|((?!32)\\d+))$""". + + # concat with tel: + ("tel:" ?result) string:concatenation ?parsedNumber . + + { + ?s schema:telephone ?number. + } e:becomes { + ?s schema:telephone ?parsedNumber. + }. + +} => { + ?s schema:telephone ?parsedNumber. +}.