List of usage examples for java.text Normalizer normalize
public static String normalize(CharSequence src, Form form)
From source file:de.ub0r.android.websms.WebSMS.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) private String removeDiacritics(final String s) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { return s; }// w ww .j av a 2 s . co m String text = Normalizer.normalize(s, Normalizer.Form.NFD); text = text.replaceAll("[^\\p{ASCII}]", ""); return text; }
From source file:org.torproject.android.service.TorService.java
public static String flattenToAscii(String string) { char[] out = new char[string.length()]; string = Normalizer.normalize(string, Normalizer.Form.NFD); int j = 0;/*from www . j ava 2s .c o m*/ for (int i = 0, n = string.length(); i < n; ++i) { char c = string.charAt(i); if (c <= '\u007F') out[j++] = c; } return new String(out); }
From source file:com.repeatability.pdf.PDFTextStripper.java
/** * Normalize certain Unicode characters. For example, convert the single "fi" ligature to "f" and "i". Also * normalises Arabic and Hebrew presentation forms. * * @param word Word to normalize//from ww w . ja va2 s.c om * @return Normalized word */ private String normalizeWord(String word) { StringBuilder builder = null; int p = 0; int q = 0; int strLength = word.length(); for (; q < strLength; q++) { // We only normalize if the codepoint is in a given range. // Otherwise, NFKC converts too many things that would cause // confusion. For example, it converts the micro symbol in // extended Latin to the value in the Greek script. We normalize // the Unicode Alphabetic and Arabic A&B Presentation forms. char c = word.charAt(q); if (0xFB00 <= c && c <= 0xFDFF || 0xFE70 <= c && c <= 0xFEFF) { if (builder == null) { builder = new StringBuilder(strLength * 2); } builder.append(word.substring(p, q)); // Some fonts map U+FDF2 differently than the Unicode spec. // They add an extra U+0627 character to compensate. // This removes the extra character for those fonts. if (c == 0xFDF2 && q > 0 && (word.charAt(q - 1) == 0x0627 || word.charAt(q - 1) == 0xFE8D)) { builder.append("\u0644\u0644\u0647"); } else { // Trim because some decompositions have an extra space, such as U+FC5E builder.append(Normalizer.normalize(word.substring(q, q + 1), Normalizer.Form.NFKC).trim()); } p = q + 1; } } if (builder == null) { return handleDirection(word); } else { builder.append(word.substring(p, q)); return handleDirection(builder.toString()); } }
From source file:ca.uhn.fhir.jpa.dao.BaseHapiFhirDao.java
public static String normalizeString(String theString) { char[] out = new char[theString.length()]; /*/*from w ww . j a v a2 s .co m*/ * The following block of code is used to strip out diacritical marks from latin script * and also convert to upper case. E.g. "jmes" becomes "JAMES". * * See http://www.unicode.org/charts/PDF/U0300.pdf for the logic * behind stripping 0300-036F * * See #454 for an issue where we were completely stripping non latin characters */ String string = Normalizer.normalize(theString, Normalizer.Form.NFD); int j = 0; for (int i = 0, n = string.length(); i < n; ++i) { char c = string.charAt(i); if (c >= '\u0300' && c <= '\u036F') { continue; } else { out[j++] = c; } } return new String(out).toUpperCase(); }
From source file:org.disit.servicemap.api.ServiceMapApi.java
public void queryMunicipalityServices(JspWriter out, RepositoryConnection con, String selection, String categorie, String textToSearch, String risultatiBus, String risultatiSensori, String risultatiServizi) throws Exception { Configuration conf = Configuration.getInstance(); String sparqlType = conf.get("sparqlType", "virtuoso"); String km4cVersion = conf.get("km4cVersion", "new"); List<String> listaCategorie = new ArrayList<>(); if (categorie != null && !"".equals(categorie)) { String[] arrayCategorie = categorie.split(";"); // GESTIONE CATEGORIE listaCategorie = Arrays.asList(arrayCategorie); }//from w ww.java 2s . co m String nomeComune = selection.substring(selection.indexOf("COMUNE di") + 10); String filtroLocalita = ""; filtroLocalita += "{ ?ser km4c:hasAccess ?entry . "; filtroLocalita += " ?entry geo:lat ?elat . "; filtroLocalita += " FILTER (?elat>40) "; filtroLocalita += " ?entry geo:long ?elong . "; filtroLocalita += " FILTER (?elong>10) "; filtroLocalita += " ?nc km4c:hasExternalAccess ?entry . "; filtroLocalita += " ?nc km4c:belongToRoad ?road . "; filtroLocalita += " ?road km4c:inMunicipalityOf ?mun . "; filtroLocalita += "?mun foaf:name \"" + nomeComune + "\"^^xsd:string . }"; filtroLocalita += "UNION"; filtroLocalita += "{"; filtroLocalita += "?ser km4c:isInRoad ?road . "; filtroLocalita += " ?ser geo:lat ?elat . "; filtroLocalita += " FILTER (?elat>40) "; filtroLocalita += " ?ser geo:long ?elong . "; filtroLocalita += " FILTER (?elong>10) "; filtroLocalita += "?road km4c:inMunicipalityOf ?mun . "; filtroLocalita += "?mun foaf:name \"" + nomeComune + "\"^^xsd:string . "; filtroLocalita += "}"; String fc = ""; try { fc = ServiceMap.filterServices(listaCategorie); } catch (Exception e) { e.printStackTrace(); } int b = 0; int numeroBus = 0; //if (listaCategorie.contains("NearBusStops")) { OLD if (listaCategorie.contains("BusStop")) { String queryString = "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX schema:<http://schema.org/#>\n" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>\n" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "SELECT DISTINCT ?bs ?nomeFermata ?bslat ?bslong ?x WHERE {\n" + " ?bs rdf:type km4c:BusStop.\n" + " ?bs foaf:name ?nomeFermata.\n" + ServiceMap.textSearchQueryFragment("?bs", "foaf:name", textToSearch) //+ " FILTER ( datatype(?nomeFermata ) = xsd:string ).\n" + " ?bs geo:lat ?bslat.\n" //+ " FILTER (?bslat>40)\n" //+ " FILTER ( datatype(?bslat ) = xsd:float )\n" + " ?bs geo:long ?bslong.\n" //+ " FILTER ( datatype(?bslong ) = xsd:float )\n" //+ " FILTER (?bslong>10)\n" + " ?bs km4c:isInMunicipality ?com.\n" + " ?com foaf:name \"" + nomeComune + "\"^^xsd:string.\n" + "}"; if (!risultatiBus.equals("0")) { queryString += " LIMIT " + risultatiBus; } TupleQuery tupleQueryBusStop = con.prepareTupleQuery(QueryLanguage.SPARQL, filterQuery(queryString, km4cVersion)); TupleQueryResult resultBS = tupleQueryBusStop.evaluate(); ServiceMap.logQuery(queryString, "API-fermate", sparqlType, nomeComune + ";" + textToSearch, 0); out.println("{\"Fermate\": "); out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); while (resultBS.hasNext()) { BindingSet bindingSetBS = resultBS.next(); String valueOfBS = bindingSetBS.getValue("bs").stringValue(); String valueOfNomeFermata = bindingSetBS.getValue("nomeFermata").stringValue(); String valueOfBSLat = bindingSetBS.getValue("bslat").stringValue(); String valueOfBSLong = bindingSetBS.getValue("bslong").stringValue(); if (b != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfBSLong + ", " + " " + valueOfBSLat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfNomeFermata) + "\", " + " \"tipo\": \"fermata\", " + " \"serviceUri\": \"" + valueOfBS + "\" " + "}, " + "\"id\": " + Integer.toString(b + 1) + " " + "}"); b++; numeroBus++; } out.println("]}"); //if (categorie.equals("NearBusStop")) { if (categorie.equals("BusStop")) { out.println("}"); } } int numeroSensori = 0; //if (listaCategorie.contains("RoadSensor")) { if (listaCategorie.contains("SensorSite")) { String queryStringSensori = "PREFIX km4c:<http://www.disit.org/km4city/schema#> " + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> " + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#> " + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX schema:<http://schema.org/#>" + "PREFIX dcterms:<http://purl.org/dc/terms/>" + "PREFIX dct:<http://purl.org/dc/terms/#>" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#> " + "PREFIX foaf:<http://xmlns.com/foaf/0.1/> " + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> " + "select distinct ?sensor ?idSensore ?lat ?long ?address ?x where{" + "?sensor rdf:type km4c:SensorSite ." + ServiceMap.textSearchQueryFragment("?sensor", "?p", textToSearch) + "?sensor geo:lat ?lat ." //+ " FILTER regex(str(?lat), \"^4\") ." + "?sensor geo:long ?long ." + "?sensor <http://purl.org/dc/terms/identifier> ?idSensore ." + "?sensor km4c:placedOnRoad ?road ." + "?road km4c:inMunicipalityOf ?mun ." + "?mun foaf:name \"" + nomeComune + "\"^^xsd:string ." + "?sensor <http://schema.org/streetAddress> ?address ." + "}"; if (!risultatiSensori.equals("0")) { queryStringSensori += " LIMIT " + risultatiSensori; } TupleQuery tupleQuerySensori = con.prepareTupleQuery(QueryLanguage.SPARQL, filterQuery(queryStringSensori, km4cVersion)); TupleQueryResult resultSensori = tupleQuerySensori.evaluate(); ServiceMap.logQuery(queryStringSensori, "API-sensori", sparqlType, nomeComune + ";" + textToSearch, 0); //if (!listaCategorie.contains("NearBusStops")) { if (!listaCategorie.contains("BusStop")) { out.println("{\"Sensori\": "); } else { out.println(",\"Sensori\":"); } out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); int s = 0; while (resultSensori.hasNext()) { // out.println(result); BindingSet bindingSetSensori = resultSensori.next(); String valueOfId = bindingSetSensori.getValue("idSensore").stringValue(); String valueOfIdService = bindingSetSensori.getValue("sensor").stringValue(); String valueOfLat = bindingSetSensori.getValue("lat").stringValue(); String valueOfLong = bindingSetSensori.getValue("long").stringValue(); String valueOfAddress = bindingSetSensori.getValue("address").stringValue(); if (s != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfLong + ", " + " " + valueOfLat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfId) + "\", " + " \"tipo\": \"sensore\", " + " \"serviceUri\": \"" + valueOfIdService + "\", " + " \"indirizzo\": \"" + escapeJSON(valueOfAddress) + "\" " + "}, " + "\"id\": " + Integer.toString(s + 1) + " " + "}"); s++; numeroSensori++; } out.println("]}"); //if (categorie.equals("RoadSensor") || categorie.equals("RoadSensor;NearBusStops")) { if (categorie.equals("SensorSite") || categorie.equals("SensorSite;BusStop")) { out.println("}"); } } int numeroServizi = 0; //if (!categorie.equals("NearBusStops") && !categorie.equals("RoadSensor") && !categorie.equals("RoadSensor;NearBusStops") && !categorie.equals("NearBusStops;RoadSensor")) { if (!categorie.equals("BusStop") && !categorie.equals("SensorSite") && !categorie.equals("SensorSite;BusStop") && !categorie.equals("BusStop;SensorSite")) { String queryStringServices = "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX schema:<http://schema.org/>\n" + "PREFIX dcterms:<http://purl.org/dc/terms/>\n" + "PREFIX dc:<http://purl.org/dc/elements/1.1/>\n" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>\n" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>\n" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n" + "SELECT distinct ?ser ?serAddress ?serNumber ?elat ?elong ?sName ?sType ?email ?note ?labelIta ?multimedia ?description ?identifier WHERE {\n" + " ?ser rdf:type km4c:Service" + (sparqlType.equals("virtuoso") ? " OPTION (inference \"urn:ontology\")" : "") + ".\n" + " OPTIONAL{?ser schema:name ?sName. }\n" + " ?ser schema:streetAddress ?serAddress.\n" + " OPTIONAL {?ser km4c:houseNumber ?serNumber}.\n" + " OPTIONAL {?ser dc:description ?description FILTER(LANG(?description) = \"it\")}\n" + " OPTIONAL {?ser km4c:multimediaResource ?multimedia }\n" + " OPTIONAL { ?ser dcterms:identifier ?identifier }\n" + " OPTIONAL {?ser skos:note ?note }\n" + " OPTIONAL {?ser schema:email ?email }\n" + ServiceMap.textSearchQueryFragment("?ser", "?p", textToSearch) + filtroLocalita + fc + " ?ser a ?sType. FILTER(?sType!=km4c:RegularService && ?sType!=km4c:Service && ?sType!=km4c:DigitalLocation && ?sType!=km4c:TransverseService)\n" + " ?sType rdfs:label ?labelIta. FILTER(LANG(?labelIta)=\"it\")\n" + "}"; if (!risultatiServizi.equals("0")) { queryStringServices += " LIMIT " + risultatiServizi; } TupleQuery tupleQueryServices = con.prepareTupleQuery(QueryLanguage.SPARQL, filterQuery(queryStringServices, km4cVersion)); TupleQueryResult resultServices = tupleQueryServices.evaluate(); ServiceMap.logQuery(queryStringServices, "API-servizi", sparqlType, nomeComune + ";" + textToSearch + ";" + categorie, 0); //if (!listaCategorie.contains("NearBusStops") && !listaCategorie.contains("RoadSensor")) { if (!listaCategorie.contains("BusStop") && !listaCategorie.contains("SensorSite")) { out.println("{\"Servizi\": "); } else { out.println(", \"Servizi\": "); } out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); int t = 0; while (resultServices.hasNext()) { BindingSet bindingSetServices = resultServices.next(); String valueOfSer = bindingSetServices.getValue("ser").stringValue(); String valueOfSName = ""; if (bindingSetServices.getValue("sName") != null) { valueOfSName = bindingSetServices.getValue("sName").stringValue(); } String valueOfSerAddress = bindingSetServices.getValue("serAddress").stringValue(); String valueOfSerNumber = ""; if (bindingSetServices.getValue("serNumber") != null) { valueOfSerNumber = bindingSetServices.getValue("serNumber").stringValue(); } String valueOfSType = bindingSetServices.getValue("sType").stringValue(); String valueOfSTypeIta = ""; if (bindingSetServices.getValue("labelIta") != null) { valueOfSTypeIta = bindingSetServices.getValue("labelIta").stringValue(); } String valueOfELat = bindingSetServices.getValue("elat").stringValue(); String valueOfELong = bindingSetServices.getValue("elong").stringValue(); String valueOfNote = ""; if (bindingSetServices.getValue("note") != null) { valueOfNote = bindingSetServices.getValue("note").stringValue(); } String valueOfEmail = ""; if (bindingSetServices.getValue("email") != null) { valueOfEmail = bindingSetServices.getValue("email").stringValue(); } //valueOfSTypeIta = Character.toLowerCase(valueOfSTypeIta.charAt(0)) + valueOfSTypeIta.substring(1); valueOfSTypeIta = valueOfSTypeIta.replace(" ", "_"); valueOfSTypeIta = valueOfSTypeIta.replace("'", ""); Normalizer.normalize(valueOfNote, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", ""); valueOfNote = valueOfNote.replaceAll("[^A-Za-z0-9 ]+", ""); valueOfEmail = valueOfEmail.replace("\"^^<http://www.w3.org/2001/XMLSchema#string>", ""); valueOfEmail = valueOfEmail.replace("\"", ""); if (t != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfELong + ", " + " " + valueOfELat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfSName) + "\", " + " \"tipo\": \"" + escapeJSON(valueOfSTypeIta) + "\", " + " \"email\": \"" + valueOfEmail + "\", " + " \"note\": \"" + escapeJSON(valueOfNote) + "\", " + " \"serviceUri\": \"" + valueOfSer + "\", " + " \"indirizzo\": \"" + escapeJSON(valueOfSerAddress) + "\", \"numero\": \"" + escapeJSON(valueOfSerNumber) + "\" " + "}, " + "\"id\": " + Integer.toString(t + 1) + " " + "}"); t++; numeroServizi++; } out.println("]}}"); } }
From source file:org.disit.servicemap.api.ServiceMapApi.java
public void queryLatLngServices(JspWriter out, RepositoryConnection con, String[] coords, String categorie, String textToSearch, String raggioBus, String raggioSensori, String raggioServizi, String risultatiBus, String risultatiSensori, String risultatiServizi) throws Exception { Configuration conf = Configuration.getInstance(); String sparqlType = conf.get("sparqlType", "virtuoso"); String km4cVersion = conf.get("km4cVersion", "new"); List<String> listaCategorieServizi = new ArrayList<String>(); if (categorie != null) { String[] arrayCategorie = categorie.split(";"); // GESTIONE CATEGORIE listaCategorieServizi = Arrays.asList(arrayCategorie); }// w w w . ja v a 2 s .co m String fc = ""; try { fc = ServiceMap.filterServices(listaCategorieServizi); } catch (Exception e) { } int i = 0; int numeroBus = 0; //if (listaCategorieServizi.contains("NearBusStops")) { if (listaCategorieServizi.contains("BusStop")) { String queryStringNearBusStop = "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX schema:<http://schema.org/#>\n" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>\n" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>\n" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n" + "SELECT DISTINCT ?bs (STR(?nome) AS ?nomeFermata) ?bslat ?bslong ?x WHERE {\n" + " ?bs geo:lat ?bslat.\n" + " ?bs geo:long ?bslong.\n" + ServiceMap.geoSearchQueryFragment("?bs", coords, raggioBus) + " ?bs rdf:type km4c:BusStop.\n" + " ?bs foaf:name ?nome.\n" + ServiceMap.textSearchQueryFragment("?bs", "foaf:name", textToSearch) + (km4cVersion.equals("old") ? " FILTER ( datatype(?bslat ) = xsd:float )\n" + " FILTER ( datatype(?bslong ) = xsd:float )\n" : "") + "} ORDER BY ?dist"; if (!risultatiBus.equals("0")) { queryStringNearBusStop += " LIMIT " + risultatiBus; } TupleQuery tupleQueryNearBusStop = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringNearBusStop); TupleQueryResult resultNearBS = tupleQueryNearBusStop.evaluate(); out.println("{\"Fermate\": "); out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); int s = 0; while (resultNearBS.hasNext()) { BindingSet bindingSetNearBS = resultNearBS.next(); String valueOfBS = bindingSetNearBS.getValue("bs").stringValue(); String valueOfNomeFermata = bindingSetNearBS.getValue("nomeFermata").stringValue(); String valueOfBSLat = bindingSetNearBS.getValue("bslat").stringValue(); String valueOfBSLong = bindingSetNearBS.getValue("bslong").stringValue(); /*String queryForLinee = "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource/>" + "PREFIX schema:<http://schema.org/>" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX vcard:<http://www.w3.org/2006/vcard/ns#>" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>" + "PREFIX dcterms:<http://purl.org/dc/terms/>" + "SELECT DISTINCT ?id WHERE {" + " ?tpll rdf:type km4c:PublicTransportLine." + " ?tpll dcterms:identifier ?id." + " ?tpll km4c:hasRoute ?route." + " ?route km4c:hasSection ?rs." + " ?rs km4c:endsAtStop ?bs1." + " ?rs km4c:startsAtStop ?bs2." + " { ?bs1 foaf:name \"" + valueOfNomeFermata + "\"." + " }UNION " + " {?bs2 foaf:name \"" + valueOfNomeFermata + "\" . " + " } " + "} ORDER BY ?id "; TupleQuery tupleQueryForLinee = con.prepareTupleQuery(QueryLanguage.SPARQL, queryForLinee);*/ TupleQueryResult resultLinee = queryBusLines(valueOfNomeFermata, con); String valueOfLinee = ""; if (resultLinee != null) { while (resultLinee.hasNext()) { BindingSet bindingSetLinee = resultLinee.next(); String idLinee = bindingSetLinee.getValue("id").stringValue(); valueOfLinee = valueOfLinee + " - " + idLinee; } } if (s != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfBSLong + ", " + " " + valueOfBSLat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfNomeFermata) + "\", " + " \"tipo\": \"fermata\", " // *** INSERIMENTO serviceType + " \"serviceType\": \"NearBusStop\", " + " \"linee\": \"" + valueOfLinee.substring(3) + "\", " // ********************************************** + " \"serviceUri\": \"" + valueOfBS + "\" " + "}, " + "\"id\": " + Integer.toString(s + 1) + " " + "}"); s++; numeroBus++; } out.println("]}"); //if (categorie.equals("NearBusStops")) { if (categorie.equals("BusStop")) { out.println("}"); } } int numeroSensori = 0; //if (listaCategorieServizi.contains("RoadSensor")) { if (listaCategorieServizi.contains("SensorSite")) { String queryStringNearSensori = "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX schema:<http://schema.org/>\n" + "PREFIX dcterms:<http://purl.org/dc/terms/>\n" + "PREFIX dct:<http://purl.org/dc/terms/#>\n" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>\n" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>\n" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n" + "SELECT DISTINCT ?sensor ?idSensore ?lat ?long ?address ?x WHERE {\n" + " ?sensor rdf:type km4c:SensorSite.\n" + " ?sensor geo:lat ?lat.\n" + " ?sensor geo:long ?long.\n" + " ?sensor dcterms:identifier ?idSensore.\n" + ServiceMap.textSearchQueryFragment("?sensor", "?p", textToSearch) + ServiceMap.geoSearchQueryFragment("?sensor", coords, raggioBus) + " ?sensor schema:streetAddress ?address.\n" + "} ORDER BY ?dist"; if (!risultatiSensori.equals("0")) { queryStringNearSensori += " LIMIT " + risultatiSensori; } TupleQuery tupleQuerySensori = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringNearSensori); TupleQueryResult resultNearSensori = tupleQuerySensori.evaluate(); //if (!listaCategorieServizi.contains("NearBusStops")) { if (!listaCategorieServizi.contains("BusStop")) { out.println("{\"Sensori\": "); } else { out.println(", \"Sensori\": "); } out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); while (resultNearSensori.hasNext()) { // out.println(result); BindingSet bindingSetNearSensori = resultNearSensori.next(); String valueOfId = bindingSetNearSensori.getValue("idSensore").stringValue(); String valueOfIdService = bindingSetNearSensori.getValue("sensor").stringValue(); String valueOfLat = bindingSetNearSensori.getValue("lat").stringValue(); String valueOfLong = bindingSetNearSensori.getValue("long").stringValue(); String valueOfAddress = bindingSetNearSensori.getValue("address").stringValue(); if (i != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfLong + ", " + " " + valueOfLat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfId) + "\", " + " \"tipo\": \"sensore\", " // *** INSERIMENTO serviceType + " \"serviceType\": \"RoadSensor\", " // ********************************************** + " \"serviceUri\": \"" + valueOfIdService + "\", " + " \"indirizzo\": \"" + escapeJSON(valueOfAddress) + "\" " + "}, " + "\"id\": " + Integer.toString(i + 1) + " " + "}"); i++; numeroSensori++; } out.println("]}"); //if (categorie.equals("RoadSensor")) { if (categorie.equals("SensorSite")) { out.println("}"); } } int numeroServizi = 0; //if (!categorie.equals("NearBusStops") && !categorie.equals("RoadSensor") && !categorie.equals("RoadSensor;NearBusStops") && !categorie.equals("NearBusStops;RoadSensor")) { if (!categorie.equals("BusStop") && !categorie.equals("SensorSite") && !categorie.equals("SensorSite;BusStop") && !categorie.equals("BusStop;SensorSite")) { String queryStringServiceNear = "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX schema:<http://schema.org/>\n" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>\n" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>\n" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n" + "PREFIX dc:<http://purl.org/dc/elements/1.1/>\n" + "SELECT distinct ?ser ?serAddress ?elat ?elong ?sType ?sCategory ?sTypeIta ?sName ?email ?note ?multimedia ?description ?x WHERE {\n" + " ?ser rdf:type km4c:Service" + (sparqlType.equals("virtuoso") ? " OPTION (inference \"urn:ontology\")" : "") + ".\n" + " OPTIONAL {?ser <http://schema.org/name> ?sName}\n" + " ?ser <http://schema.org/streetAddress> ?serAddress.\n" + " OPTIONAL {?ser skos:note ?note}\n" + " OPTIONAL {?ser dc:description ?description" + " FILTER(LANG(?description) = \"it\")" + " }\n" + " OPTIONAL {?ser km4c:multimediaResource ?multimedia}\n" + " OPTIONAL {?ser schema:email ?email }\n" + ServiceMap.textSearchQueryFragment("?ser", "?p", textToSearch) + " {\n" + " ?ser km4c:hasAccess ?entry.\n" + " ?entry geo:lat ?elat.\n" + " ?entry geo:long ?elong.\n" + ServiceMap.geoSearchQueryFragment("?entry", coords, raggioServizi) + " } UNION {\n" + " ?ser geo:lat ?elat.\n" + " ?ser geo:long ?elong.\n" + ServiceMap.geoSearchQueryFragment("?ser", coords, raggioServizi) + " }\n" + fc + (!km4cVersion.equals("old") ? " graph ?g {?ser a ?sType. FILTER(?sType!=km4c:RegularService && ?sType!=km4c:Service && ?sType!=km4c:DigitalLocation && ?sType!=km4c:TransverseService)}\n" + " ?sType rdfs:subClassOf ?sCategory. FILTER(?sCategory != <http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing>) " + " ?sType rdfs:label ?sTypeIta. FILTER(LANG(?sTypeIta)=\"it\")\n" : "") + "} ORDER BY ?dist"; if (!risultatiServizi.equals("0")) { queryStringServiceNear += " LIMIT " + risultatiServizi; } TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringServiceNear); TupleQueryResult result = tupleQuery.evaluate(); //if (!listaCategorieServizi.contains("NearBusStops") && !listaCategorieServizi.contains("RoadSensor")) { if (!listaCategorieServizi.contains("BusStop") && !listaCategorieServizi.contains("SensorSite")) { out.println("{\"Servizi\": "); } else { out.println(", \"Servizi\": "); } out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); int w = 0; while (result.hasNext()) { BindingSet bindingSet = result.next(); String valueOfSer = bindingSet.getValue("ser").stringValue(); String valueOfSerAddress = ""; if (bindingSet.getValue("serAddress") != null) { valueOfSerAddress = bindingSet.getValue("serAddress").stringValue(); } String valueOfSType = ""; if (bindingSet.getValue("sType") != null) { valueOfSType = bindingSet.getValue("sType").stringValue(); } String valueOfSTypeIta = ""; if (bindingSet.getValue("sTypeIta") != null) { valueOfSTypeIta = bindingSet.getValue("sTypeIta").stringValue(); //valueOfSTypeIta = Character.toLowerCase(valueOfSTypeIta.charAt(0)) + valueOfSTypeIta.substring(1); valueOfSTypeIta = valueOfSTypeIta.replace(" ", "_"); valueOfSTypeIta = valueOfSTypeIta.replace("'", ""); } // DICHIARAZIONE VARIABILI serviceType e serviceCategory per ICONA String subCategory = ""; if (bindingSet.getValue("sType") != null) { subCategory = bindingSet.getValue("sType").stringValue(); subCategory = subCategory.replace("http://www.disit.org/km4city/schema#", ""); subCategory = Character.toLowerCase(subCategory.charAt(0)) + subCategory.substring(1); subCategory = subCategory.replace(" ", "_"); } String category = ""; if (bindingSet.getValue("sCategory") != null) { category = bindingSet.getValue("sCategory").stringValue(); category = category.replace("http://www.disit.org/km4city/schema#", ""); category = Character.toLowerCase(category.charAt(0)) + category.substring(1); category = category.replace(" ", "_"); } String serviceType = category + "_" + subCategory; String valueOfSName = ""; if (bindingSet.getValue("sName") != null) { valueOfSName = bindingSet.getValue("sName").stringValue(); } else { valueOfSName = subCategory.replace("_", " ").toUpperCase(); } String valueOfELat = bindingSet.getValue("elat").stringValue(); String valueOfELong = bindingSet.getValue("elong").stringValue(); String valueOfNote = ""; if (bindingSet.getValue("note") != null) { valueOfNote = bindingSet.getValue("note").stringValue(); } String valueOfEmail = ""; if (bindingSet.getValue("email") != null) { valueOfEmail = bindingSet.getValue("email").stringValue(); } Normalizer.normalize(valueOfNote, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", ""); valueOfNote = valueOfNote.replaceAll("[^A-Za-z0-9 ]+", ""); if (w != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfELong + ", " + " " + valueOfELat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfSName) + "\", " + " \"tipo\": \"" + escapeJSON(valueOfSTypeIta) + "\", " // *** INSERIMENTO serviceType + " \"serviceType\": \"" + escapeJSON(mapServiceType(serviceType)) + "\", " // ********************************************** + " \"email\": \"" + escapeJSON(valueOfEmail) + "\", " + " \"note\": \"" + escapeJSON(valueOfNote) + "\", " + " \"serviceUri\": \"" + escapeJSON(valueOfSer) + "\", " + " \"indirizzo\": \"" + escapeJSON(valueOfSerAddress) + "\" " + "}, " + "\"id\": " + Integer.toString(w + 1) + " " + "}"); w++; numeroServizi++; } out.println("]}}"); } else { if (categorie.equals("SensorSite;BusStop") || categorie.equals("BusStop;SensorSite")) { out.println("}"); } } }
From source file:de.innovationgate.utils.WGUtils.java
/** * performs a unicode normalization to NFC form (java.text.Normalizer.Form.NFC) for the given input * @param input The input string/*from ww w . j a v a 2 s . c om*/ * @return the normalized or original value if already NFC form */ public static String normalizeUnicode(String input) { if (input != null && !Normalizer.isNormalized(input, Normalizer.Form.NFC)) { return Normalizer.normalize(input, Normalizer.Form.NFC); } return input; }
From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java
@Override public String escapeInvalidCharsEntry(String accentedString) { String decomposed = Normalizer.normalize(accentedString, Normalizer.Form.NFD); return decomposed.replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); }
From source file:com.adobe.aem.demomachine.communities.Loader.java
public static String slugify(String input) { return Normalizer.normalize(input, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "") .replaceAll("[^ \\w]", "").trim().replaceAll("\\s+", "-").toLowerCase(Locale.ENGLISH); }
From source file:org.sakaiproject.assignment.impl.BaseAssignmentService.java
public String escapeInvalidCharsEntry(String accentedString) { String decomposed = Normalizer.normalize(accentedString, Normalizer.Form.NFD); String cleanString = decomposed.replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); return cleanString; }