MAIN
MAIN
  **module** lang = py
    **MAIN**
      notation
        PROCESS ::=
          *vars
            {BEFORE}
              BEFORE = []
            {AFTER}
              AFTER = []
            {DO}
              DO = []
                nada
            {AFTER_ALL}
              AFTER_ALL = []
                for x in L
                  CASE
                    x.titre = 'BEFORE'
                      BEFORE = x
                    x.titre = 'AFTER'
                      AFTER = x
                    x.titre = 'DO'
                      DO = x
                    x.titre = 'AFTER_ALL'
                      AFTER_ALL = x
          ==> PROCESS {a1} --> {a2}
            file_in F= {a1}
              file_out F= {a2}
                {L}
            with open (file_in, 'r', encoding = 'utf8') as s_in
              with open (file_out, 'w', encoding = 'utf8') as s_out
                BEFORE
                  {BEFORE}
                while True
                  line = s_in.readline ()
                    if not line
                      break
                  {DO}
                AFTER
                  {AFTER}
          {AFTER_ALL}
        nl ::=
          s_out.write ('\n')
            {L}
        NF ::=
          {a1} = DIR_BASE J+ "{a2}"
            {L}
        ' F= ' ::= {a_1} = DIR_BASE F/ "{a1_}"
      def fact (n)
        if n < 2
          1
          else
            n * fact (n-1)
      def traite ()
        NB
          all_projects is a dict that contains all projects
        prétraitement pour fabriquer un fichier json : step3.txt
          fabrique un dictionnaire all_projects
          recopier le fichier application
            shutil.copy2 ( DIR_BASE J+ "database 1995 applications.txt", DIR_BASE J+ "step1.txt")
          split correct des lignes
            PROCESS step1.txt, step2.txt
              BEFORE
                c_line = ''
                  found = False
              DO
                split correct des lignes
                  nlines = []
                  echo line
                  if line finit par '\n'
                    line = line[:-1]
                  if line = ''
                    continue
                  line = line.lstrip ()
                    saute le début du fichier
                      if not found
                        if line commence par '<'
                          found = True
                          else
                            continue
                  les affaires courantes
                    if '<' in line
                      line = line.replace ('<', '\n<')
                    if line = ''
                      continue
                    lines = line.split ('\n')
                    for new_line in lines
                      new_line = new_line.strip ()
                        if new_line != ''
                          s_out.write (new_line)
                            nl
          recolle les lignes qui ne commencent pas par '<'
            PROCESS step2.txt, step21.txt
              BEFORE
                l_lines = []
              DO
                nettoye
                  line = line[:-1]
                  if line = ''
                    continue
                recolle plusieurs lignes similaires
                  if line commence par '<'
                    if l_lines != []
                      new_line = ' '.join (l_lines)
                        s_out.write (new_line)
                          nl
                      echo new_line
                      l_lines = [line]
                    else
                      l_lines.append (line)
                        continue
              AFTER
                if l_lines != []
                  new_line = ' '.join (l_lines)
                    s_out.write (new_line)
                      nl
          assemblage des blocs applications pour faire le dictionnaire des projets
            ici on va finaliser pour chaque programme un dictionnaire json
              et sauver en json
            PROCESS step21.txt, step3.txt
              BEFORE
                hello
                l_project = dict ()
                all_projects = {}
                all_infos = dict()
                l_numbers = [
                  "Lines"
                  "No. of Users"
                  "Number"
                  "Maintenance effort"
                  "Predicates"
                  "Users"
              DO
                nettoye
                  line = line[:-1]
                assemblage des blocs applications
                  CASE
                    line commence par '<Program'
                      nouveau projet
                        echo line
                        if '>' in line
                          récupère le après
                            line = line.split ('>', 1)[1].strip ()
                        l_projet = dict ()
                        l_project ['Program'] = line
                        all_projects [line] = l_project
                      continue
                    line commence par '</Program'
                      nouveau projet
                        echo l_project
                          l_project = dict ()
                      continue
                    if '>' in line
                      récupère le après
                        info, data = line.split ('>', 1)
                          info = info[1:].strip ()
                            data = data.strip()
                            tranforme en integer etc
                              if info in l_numbers
                                try
                                  data = int(data)
                                  except
                                    pass
                          l_project[info] = data
                            all_infos [info] = data
              AFTER_ALL
                un peu de trace
                  echo len (all_projects)
                    echo all_infos
                      for info in sorted (all_infos.keys ())
                        print (info, '-->', all_infos [info])
                sauve en json
                  dict_to_file (all_projects, file_out)
        post_processing
          récupérer la liste des projet
            DIR_BASE = "D:/LG SAVOIRS/PROLOG/DOCS/APPLICATIONS/NEW_APPLICATIONS"
          liste_projets = os.listdir (DIR_BASE)
            echo_list liste_projets
          filtrage
            working_list = [
              'data_d2.json'
              'data_base_low.json'
              'domains.json'
            liste_projets = [f for f in liste_projets if f finit par '.json' and f not in working_list]
            echo_list liste_projets
          fabrication du dictionnaire global
            all_projects = {}
              for f in liste_projets
                all_projects [k] = d
                  WHERE
                    d = dict_from_file (DIR_BASE F/ f)
                    k = f[:-5]
            f_data_d2 = DIR_BASE F/ 'data_d2.json'
            dict_to_file (all_projects , f_data_d2)
          fabrication des minuscules
            tout mettre en minuscules dans un all_project_low, sauf le nom du projet pour la clef
              all_projects_low = dict ()
              for p, p_d in all_projects.items ()
                np = dict ()
                  all_projects_low [p] = np
                for k, value in p_d.items ()
                  if k != 'Program'
                    if value est une chaine
                      np [k] = value.lower ()
                  np [k] = value
              echo len (all_projects), len (all_projects_low)
              data_base_low F= data_base_low.json
              dict_to_file (all_projects_low, data_base_low)
          traitement des dates
            rajoute le champ year_deployed = juste l'année
              fields = [
                "year"
                "when deployed"
                "references"
                "information date"
                "description"
                "range_deployed"
                "range_development"
              for name, project in all_projects.items ()
                M = 1900
                  def best_date (S, field = '')
                    DESCRIPTION
                      essaye de trouver une date réaliste, prend la première qui convient
                    M = 1900
                    if not S or S = ''
                      M
                    l_nums = []
                      split the line
                        for c in S
                          CASE
                            c in ('1234567890')
                              l_nums.append (c)
                            else
                              l_nums.append (' ')
                      s_new = ''.join(l_nums)
                        l_nums = s_new.split (' ')
                          echo l_nums
                        l_nums = [int(x) for x in l_nums if x != '']
                        l_nums = [x for x in l_nums if x < 2100]
                        echo l_nums
                    if l_nums != []
                      l_nums = [x for x in l_nums if x > 1900]
                        if field = 'year'
                          M = min (map (int, l_nums))
                          else
                            M = max (map (int, l_nums))
                    if 31 < M < 100
                      M += 1900
                    echo S, M, l_nums
                    M
                echo name
                for field in fields
                  if M != 1900
                    break
                      S = project.get ("when deployed", False)
                  S2 = project.get (field, False)
                  M2 = best_date (S2, field)
                    echo field, S2, M2
                      if M2 != 1900
                        if field = 'year'
                          M = M2
                            break
                  if M2 > M
                    M = M2
                project ['year_deployed'] = M
              data_f2 F= data_d2.json
                dict_to_file (all_projects, data_f2)
          un peu de visu de data
            domains = {
              "Business" : {
                "kw" : [
                  "sales"
                  "sell"
                  "sold"
                  "business"
                  "brand"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
                  "When Deployed"
              "Classification" : {
                "kw" : [
                  "classif"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
              "Decision" : {
                "kw" : [
                  "decision"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
                  "organization"
              "Design" : {
                "kw" : [
                  "engineering"
                  "architecture"
                  "CAD"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
              "Engineering" :{
                "kw" : [
                  "engineering"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
                  "organization"
              "Expert Systems" :{
                "kw" : [
                  "expert"
                  "advis"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
                  "organization"
              "Finance" : {
                "kw" : [
                  "loan"
                    "bank"
                      "credit"
                  "financ"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
              "Generation of documents and programs" :{
                "kw" : [
                  "generat"
                  "document"
                  "parse"
                  "parsing"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
              "Health" :{
                "kw" : [
                  "health"
                  "medicine"
                  "medical"
                  "drug"
                  "patholog"
                  "therap"
                "fields" : [
                  "purpose"
                  "description"
              "Knowledge Management" :{
                "kw" : [
                  "knowledge"
                  "representation"
                  "expert system"
                  "intelligence"
                  "ontolog"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
                  "organization"
              "Legal" :{
                "kw" : [
                  "legal"
                  "law"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
              "Operations" :{
                "kw" : [
                  "operations"
                  "activit"
                  "process"
                  "daily"
                  "monthly"
                  "real-time"
                "fields" : [
                  "purpose"
                  "description"
                  "references"
              "Problem solving" :{
                "kw" : [
                  "sales"
                  "customer"
                  "problem"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
              "Programming" :{
                "kw" : [
                  "program"
                  "language"
                  "compil"
                  "software"
                  "specification"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
              "Real-Time" : {
                "kw" : [
                  "real-time"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
              "Research" :{
                "kw" : [
                  "university"
                  "research"
                  "proof"
                  "proving"
                  "formal"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
                  "organization"
              "Scheduling" : {
                "kw" : [
                  "schedul"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
                  "organization"
              "Speech" :{
                "kw" : [
                  "speech"
                "fields" : [
                  "domain"
                  "purpose"
                  "description"
                  "references"
              "Teaching" :{
                "kw" : [
                  "teach"
                  "educat"
                "fields" : [
                  "purpose"
                  "description"
                  "domain"
                  "references"
              "Tools" :{
                "kw" : [
                  "tool"
                  "platform"
                "fields" : [
                  "purpose"
                  "description"
            echo domains
          lecture de data_f2 en retour pour vérification
            try
              db = file_to_dict (data_f2)
                echo db
                echo data_f2
              except
                print ('*********************** error in read data_f2 ****************')
          compréhension par domaine
            for domain in domains
              print ('>>> ===================', domain, '========================' )
              infos = domains [domain]
                kw_list = infos ["kw" ]
                  echo kw_list
                fields_list = infos ["fields"]
                  echo fields_list
              if 'results' not in infos
                infos ['results'] = results = []
              results = infos ['results']
              for project, project_d in all_projects_low.items ()
                found = False
                  echo project, project_d
                for field in fields_list
                  field_line = project_d .get (field, False)
                    if not field_line
                      continue
                    field_line = field_line.lower ()
                  for kw in kw_list
                    echo field, kw, field_line
                    if kw in field_line
                      found = True
                        break
                if found
                  echo project , domain
                    pass
                  results.append ( (project, project_d.get ('domain', 'unknown domain'), field, kw))
                    echo '----- found !',kw, 'in', field, ':', field_line
              print (domain, len(infos ['results']), infos ['results'])
              print ('<<< ===================', domain, '========================', len (infos['results']))
            sauvegarde
              domain_f F= domains.json
                dict_to_file (domains, domain_f)
          lancement de la génération du fichier html décrit en XMIND
            *exec
              fichier_once = "D:\\KM2\\KM2_SYSTEM\\KM2_PROCESS_ONCE.txt"
                print (u'______________ géneration fichier database ?? -----------------------------')
              try
                with open (fichier_once, 'w', encoding = 'utf8') as f_out
                  line = f_name + ',' + f_inst
                    WHERE
                      f_name = "D:\\LG SAVOIRS\\PROLOG\\DOCS\\APPLICATIONS\\NEW_APPLICATIONS\\PROCESSING NEW APPLICATIONS IN PROLOG.xmind"
                      f_inst = "force, htm"
                      echo f_name, f_inst
                  echo line
                  f_out.write (line)
                print (u'______________ géneration fichier database ok -----------------------------')
                except
                  print (u'**************** pb dans le géneration fichier database ***************')
      traite ()
      FIN
        for i in range (10)
          print ( int ( '0' + str(i)))
  ici
    PROCESSING OLD APPLICATIONS IN PROLOG.bat
  regeneration