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 J+ "{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
          data_file F= step3.txt
            all_projects = dict_from_file (data_file)
              echo len (all_projects)
          fabrication des minuscules
            tout mettre en minuscules ans 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 = [
                "When Deployed"
                "References"
                "Information Date"
                "Description"
              for name, project in all_projects.items ()
                M = 1900
                  def best_date (S)
                    M = 1900
                    if not S or S = ''
                      M
                    l_nums = []
                      for c in S
                        CASE
                          c in ' /,.'
                            l_nums.append (' ')
                          c in ('1234567890')
                            l_nums.append (c)
                      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]
                    if l_nums != []
                      M = max (map (int, l_nums))
                    if 31 < M < 100
                      M += 1900
                    echo S, M, l_nums
                    M
                for field in fields
                  if M != 1900
                    break
                      S = project.get ("When Deployed", False)
                  S2 = project.get (field, False)
                  M2 = best_date (S2)
                  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"
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
                  "When Deployed"
              "Classification" : {
                "kw" : [
                  "classif"
                "fields" : [
                  "Purpose"
                  "Description"
                  "Domain"
                  "References"
              "Design" : {
                "kw" : [
                  "engineering"
                  "architecture"
                  "CAD"
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
              "Engineering" :{
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
                  "Organization"
                "kw" : [
                  "engineering"
              "Expert Systems" :{
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
                  "Organization"
                "kw" : [
                  "expert"
              "Finance" : {
                "kw" : [
                  "loan"
                    "bank"
                      "credit"
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
              "Generation of documents and programs" :{
                "kw" : [
                  "generation"
                  "document"
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
              "Health" :{
                "fields" : [
                  "Purpose"
                  "Description"
                  "Domain"
                  "References"
                "kw" : [
                  "health"
                  "medicine"
                  "medical"
                  "drug"
                  "patholog"
                  "therap"
              "Knowledge Management" :{
                "kw" : [
                  "knowledge"
                  "representation"
                  "expert system"
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
                  "Organization"
              "Legal" :{
                "fields" : [
                  "Purpose"
                  "Description"
                  "Domain"
                  "References"
                "kw" : [
                  "legal"
                  "law"
              "Operations" :{
                "fields" : [
                  "Purpose"
                  "Description"
                  "Domain"
                  "References"
                "kw" : [
                  "operations"
                  "activit"
                  "process"
                  "daily"
                  "monthly"
                  "real-time"
              "Problem solving" :{
                "kw" : [
                  "sales"
                  "customer"
                  "problem"
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
              "Programming" :{
                "kw" : [
                  "program"
                  "language"
                  "compil"
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
              "Real-Time" : {
                "kw" : [
                  "real-time"
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
              "Research" :{
                "kw" : [
                  "university"
                  "research"
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
                  "Organization"
              "Scheduling" : {
                "kw" : [
                  "schedul"
                "fields" : [
                  "Organization"
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
              "Speech" :{
                "kw" : [
                  "speech"
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                  "References"
              "Teaching" :{
                "fields" : [
                  "Purpose"
                  "Description"
                "kw" : [
                  "teaching"
                  "education"
              "Tools" :{
                "fields" : [
                  "Domain"
                  "Purpose"
                  "Description"
                "kw" : [
                  "tool"
                  "platform"
            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
              infos = domains [domain]
                kw_list = infos ["kw" ]
                fields_list = infos ["fields"]
              if 'results' not in infos
                infos ['results'] = []
              for p, p_d in all_projects_low.items ()
                found = False
                for field in fields_list
                  field_line = p_d .get (field, False)
                    if not field_line
                      continue
                  for kw in kw_list
                    if kw in field_line
                      found = True
                        break
                  if found
                    break
                if found
                  echo p , domain
                    pass
                  results = infos ['results']
                  results.append ( (p_d ['Program'], field, kw))
                    results.append ( (p, p_d ['Domain'], field, kw))
              print ('===================', domain, '========================', len (infos['results']))
              print (domain, len(infos ['results']), infos ['results'])
            sauvegarde
              domain_f F= domains.json
                dict_to_file (domains, domain_f)
      traite ()
      FIN
        for i in range (10)
          print ( int ( '0' + str(i)))
  ici
    PROCESSING OLD APPLICATIONS IN PROLOG.bat