From 8c211ceb52a6b007cfdeb9461aeba3b7d85ad583 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Fri, 19 Jan 2024 15:52:36 -0700 Subject: [PATCH] Queries Smart Data Models for smarter code suggestions --- .../computate/frFR/java/EcrireGenClasse.java | 111 +++++++++--------- .../computate/frFR/java/IndexerClasse.java | 39 +++++- 2 files changed, 91 insertions(+), 59 deletions(-) diff --git a/src/main/java/org/computate/frFR/java/EcrireGenClasse.java b/src/main/java/org/computate/frFR/java/EcrireGenClasse.java index 43631ba7..12f8cb43 100644 --- a/src/main/java/org/computate/frFR/java/EcrireGenClasse.java +++ b/src/main/java/org/computate/frFR/java/EcrireGenClasse.java @@ -6359,47 +6359,49 @@ public void ecrireClasseCommentaire(JsonObject langueConfig, String siteNom, Str if(classeSmartDataModel != null && !classeFiware) { File smartDataModelSpecFile = new File(System.getenv("HOME"), String.format(".local/src/smart-data-models/%s/dataModel.%s/%s/model.yaml", classeSmartDataDomain, classeSmartDataSubModule, classeSmartDataModel)); if(smartDataModelSpecFile.exists()) { + ToutEcrivain wSmartDataModel = ToutEcrivain.create(); Yaml yaml = new Yaml(); Map map = yaml.load(FileUtils.readFileToString(smartDataModelSpecFile, StandardCharsets.UTF_8)); JsonObject spec = new JsonObject(map); JsonObject properties = spec.getJsonObject(classeSmartDataModel).getJsonObject("properties"); - l(); - tl(0, " *

FIWARE SmartDataModel fields:

"); + wSmartDataModel.l(); + wSmartDataModel.tl(0, "FIWARE SmartDataModel fields:"); + wSmartDataModel.l(); - l(" * {@literal /}{@literal **}
"); - l(" * {@literal * SmartDataModel: ", classeSmartDataModel, " - ", classeSmartDataSubModule, " - ", classeSmartDataDomain, "}
"); - l(" * {@literal * Fiware: true}
"); - l(" *
"); - l(" * {@literal * Model: true}
"); - l(" * {@literal * SqlOrder: 1}
"); - l(" * {@literal * Api: true}
"); - l(" * {@literal * Page: true}
"); - l(" * {@literal * SuperPage.enUS: BaseModelPage}
"); - l(" * {@literal * Indexed: true}
"); - l(" * {@literal * Order: 1}
"); - l(" * {@literal * Description: }
"); - l(" * {@literal * ApiTag.enUS: ", classeNomSimple, "}
"); - l(" * {@literal * ApiUri.enUS: /api/", classeNomSimple, "}
"); - l(" *
"); - l(" * {@literal * ApiMethod.enUS: Search}
"); - l(" * {@literal * ApiMethod: GET}
"); - l(" * {@literal * ApiMethod: PATCH}
"); - l(" * {@literal * ApiMethod: POST}
"); - l(" * {@literal * ApiMethod: PUTImport}
"); - l(" *
"); - l(" * {@literal * ApiMethod.enUS: SearchPage}
"); - l(" * {@literal * Page.SearchPage.enUS: ", classeNomSimple, "Page}
"); - l(" * {@literal * ApiUri.SearchPage.enUS: /", classeNomSimple, "}
"); - l(" *
"); - l(" * {@literal * Role.enUS: SiteAdmin}
"); - l(" *
"); - l(" * {@literal * AName.enUS: a ", classeNomSimple, "}
"); - l(" * {@literal * Color: 2017-shaded-spruce}
"); - l(" * {@literal * IconGroup: duotone}
"); - l(" * {@literal * IconName: map-location-dot}
"); - l(" * {@literal * Rows: 100}
"); - l(" * {@literal **}{@literal /}
"); - l(" * {@literal public class ", classeNomSimple, " extends ", classeNomSimple, "Gen} {
"); + wSmartDataModel.l("/**"); + wSmartDataModel.l(" * SmartDataModel: ", classeSmartDataModel, " - ", classeSmartDataSubModule, " - ", classeSmartDataDomain); + wSmartDataModel.l(" * Fiware: true"); + wSmartDataModel.l(" *"); + wSmartDataModel.l(" * Model: true"); + wSmartDataModel.l(" * SqlOrder: 1"); + wSmartDataModel.l(" * Api: true"); + wSmartDataModel.l(" * Page: true"); + wSmartDataModel.l(" * SuperPage.enUS: BaseModelPage"); + wSmartDataModel.l(" * Indexed: true"); + wSmartDataModel.l(" * Order: 1"); + wSmartDataModel.l(" * Description: "); + wSmartDataModel.l(" * ApiTag.enUS: ", classeNomSimple); + wSmartDataModel.l(" * ApiUri.enUS: /api/", classeNomSimple); + wSmartDataModel.l(" *"); + wSmartDataModel.l(" * ApiMethod.enUS: Search"); + wSmartDataModel.l(" * ApiMethod: GET"); + wSmartDataModel.l(" * ApiMethod: PATCH"); + wSmartDataModel.l(" * ApiMethod: POST"); + wSmartDataModel.l(" * ApiMethod: PUTImport"); + wSmartDataModel.l(" *"); + wSmartDataModel.l(" * ApiMethod.enUS: SearchPage"); + wSmartDataModel.l(" * Page.SearchPage.enUS: ", classeNomSimple, "Page"); + wSmartDataModel.l(" * ApiUri.SearchPage.enUS: /", classeNomSimple); + wSmartDataModel.l(" *"); + wSmartDataModel.l(" * Role.enUS: SiteAdmin"); + wSmartDataModel.l(" *"); + wSmartDataModel.l(" * AName.enUS: a ", classeNomSimple); + wSmartDataModel.l(" * Color: 2017-shaded-spruce"); + wSmartDataModel.l(" * IconGroup: duotone"); + wSmartDataModel.l(" * IconName: map-location-dot"); + wSmartDataModel.l(" * Rows: 100"); + wSmartDataModel.l(" **/"); + wSmartDataModel.l("public class ", classeNomSimple, " extends ", classeNomSimple, "Gen {"); Integer row = 3; Integer cell = 1; @@ -6423,36 +6425,37 @@ else if("number".equals(jsonType)) javaType = "BigDecimal"; else if("location".equals(fieldName)) javaType = "Path"; - l(" *
"); - l(" * {@literal /**}
"); - l(" * {@literal * {@inheritDoc}}
"); + wSmartDataModel.l(); + wSmartDataModel.l(" /**"); + wSmartDataModel.l(" * {@inheritDoc}"); if("areaServed".equals(fieldName)) { - l(" * {@literal * FiwareType: geo:linestring}
"); - l(" * {@literal * Location: true}
"); + wSmartDataModel.l(" * FiwareType: geo:linestring"); + wSmartDataModel.l(" * Location: true"); } if("location".equals(fieldName)) { - l(" * {@literal * FiwareType: geo:point}
"); + wSmartDataModel.l(" * FiwareType: geo:point"); } - l(" * {@literal * DocValues: true}
"); - l(" * {@literal * Persist: true}
"); - l(" * {@literal * DisplayName: ", StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(fieldName), " ").toLowerCase(), "}
"); + wSmartDataModel.l(" * DocValues: true"); + wSmartDataModel.l(" * Persist: true"); + wSmartDataModel.l(" * DisplayName: ", StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(fieldName), " ").toLowerCase(), ""); if(description != null) - l(" * {@literal * Description: ", description.replace("\r\n", " ").replace("\n", " "), "}
"); - l(" * {@literal * HtmRow: ", row, "}
"); - l(" * {@literal * HtmCell: ", cell, "}
"); - l(" * {@literal * Facet: true}
"); - l(" * {@literal **}{@literal /}
"); - l(" * {@literal protected void _", fieldName, "(Wrap<", javaType, "> w)} {}
"); + wSmartDataModel.l(" * Description: ", description.replace("\r\n", " ").replace("\n", " "), ""); + wSmartDataModel.l(" * HtmRow: ", row, ""); + wSmartDataModel.l(" * HtmCell: ", cell, ""); + wSmartDataModel.l(" * Facet: true"); + wSmartDataModel.l(" **/"); + wSmartDataModel.l(" protected void _", fieldName, "(Wrap<", javaType, "> w) {}"); cell++; if(cell > 3) { row++; cell = 1; } + wSmartDataModel.l(); } } - l(" * }
"); - - l(); + wSmartDataModel.l("}"); + wSmartDataModel.l(); + System.out.println(wSmartDataModel); } } } catch(Exception ex) { diff --git a/src/main/java/org/computate/frFR/java/IndexerClasse.java b/src/main/java/org/computate/frFR/java/IndexerClasse.java index eedcddde..b29e2bb4 100644 --- a/src/main/java/org/computate/frFR/java/IndexerClasse.java +++ b/src/main/java/org/computate/frFR/java/IndexerClasse.java @@ -15,9 +15,11 @@ import java.awt.image.BufferedImage; import java.io.File; +import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; +import java.net.URLEncoder; import java.sql.Timestamp; import java.text.Normalizer; import java.text.NumberFormat; @@ -52,6 +54,7 @@ import javax.imageio.ImageIO; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.configuration2.YAMLConfiguration; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; @@ -91,6 +94,7 @@ import com.thoughtworks.qdox.model.impl.DefaultJavaParameterizedType; import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; /** * NomCanonique.enUS: org.computate.enUS.java.IndexClass @@ -5385,11 +5389,28 @@ else if(langueConfig.getString(ConfigCles.var_PUTFusion).equals(classeApiMethode String classeSmartDataModelStr = regex("^SmartDataModel:\\s(.*)", classeCommentaire); if(classeSmartDataModelStr != null) { - Matcher m = Pattern.compile("([\\w ]+) - ([\\w ]+) - ([\\w ]+)").matcher(classeCommentaire); - if (m.find()) { - indexerStockerSolr(classeDoc, "classeSmartDataDomain", m.group(3).replace(" ", "").trim()); - indexerStockerSolr(classeDoc, "classeSmartDataSubModule", m.group(2).trim()); - indexerStockerSolr(classeDoc, "classeSmartDataModel", m.group(1).trim()); + String encodedStr = "\"" + Arrays.asList(classeSmartDataModelStr.replaceAll("([a-z])([A-Z])", "$1 $2").split(" +")).stream().map(s -> encodeUrl(s)).collect(Collectors.joining("\" OR \"")) + "\""; + System.out.println(encodedStr); + SolrQuery rechercheSolr = new SolrQuery(); + rechercheSolr.setQuery("domainName_suggested:" + encodedStr + "^2 OR domainName_text_enUS:" + encodedStr + "^5 OR submoduleShortName_suggested:" + encodedStr + "^3 OR submoduleShortName_text_enUS:" + encodedStr + "^10 OR modelName_suggested:" + encodedStr + "^3 OR modelName_text_enUS:" + encodedStr + "^20&fl=*,score&sort=score desc"); + rechercheSolr.setRows(10); + rechercheSolr.addFilterQuery("computateFiwareSmartDataModel_docvalues_boolean:true"); + rechercheSolr.setIncludeScore(true); + QueryResponse reponseRecherche = clientSolrComputate.query(rechercheSolr); + SolrDocumentList listeRecherche = reponseRecherche.getResults(); + if(listeRecherche.size() > 0) { + SolrDocument doc = listeRecherche.get(0); + indexerStockerSolr(classeDoc, "classeSmartDataDomain", doc.getFieldValue("domainName_docvalues_string").toString().replace(" ", "").trim()); + indexerStockerSolr(classeDoc, "classeSmartDataSubModule", doc.getFieldValue("submoduleShortName_docvalues_string").toString().trim()); + indexerStockerSolr(classeDoc, "classeSmartDataModel", doc.getFieldValue("modelName_docvalues_string").toString().trim()); + System.out.println(String.format("Top %s Smart Data Model results were: ", listeRecherche.size())); + System.out.println(String.format("Model - Submodule - Domain - score", listeRecherche.size())); + System.out.println(String.format("--------------------------", listeRecherche.size())); + for(Integer i = 0; i < listeRecherche.size(); i++) { + SolrDocument model = listeRecherche.get(i); + System.out.println(String.format("%s. %s %s %s %s", String.format("%02d", (i + 1)), model.getFieldValue("modelName_docvalues_string"), model.getFieldValue("submoduleShortName_docvalues_string"), model.getFieldValue("domainName_docvalues_string"), model.getFieldValue("score"))); + } + System.out.println(" "); } } @@ -5760,4 +5781,12 @@ else if("enUS".equals(langueNom)) { clientSolrComputate.commit(false, false, true); return classeDoc; } + + public String encodeUrl(String s) { + try { + return URLEncoder.encode(s, "UTF-8"); + } catch (UnsupportedEncodingException e) { + return ""; + } + } }