gluc / ahp

Analytical Hierarchy Process (AHP) with R
97 stars 41 forks source link

how to support utf-8 character in yaml file? #19

Open jjcizi opened 6 years ago

jjcizi commented 6 years ago

First, your package is great! But, your package can not support utf-8 character in yaml file. It means a lot of people cant not use their home language to show results. Can you fix this? Please. Or tell me how to solve this problem.

gluc commented 6 years ago

Not sure why you believe it doesn't work. Using the the online app at https://ipub.com/dev-corner/apps/ahp/ the following works perfectly fine:

Version: 2.0
Alternatives: &alternatives
  Beach:
    cost: 10000
  Montañas:
    cost: 5000
Goal:
  name: Vacation
  decision-makers:
    #optional node, needed only if not all decision-makers have equal voting power
    - Däd: 0.4
    - Mom: 2/5
    - Kid: 0.2
  preferences:
    Däd:
      pairwise:
      - [Costs, Fön, 4]
      - [Costs, Spa, 9]
      - [Fön, Spa, 4]
    Mom:
      pairwise:
      - [Costs, Fön, 1/4]
      - [Costs, Spa, 1/9]
      - [Fön, Spa, 1/5]
    Kid:
      pairwise:
      - [Costs, Fön, 1/9]
      - [Costs, Spa, 1]
      - [Fön, Spa, 9]
  children:
    Costs:
      preferences:
        Däd:
          pairwiseFunction: 
            function(a1, a2) min(9, max(1/9, a2$cost/a1$cost))
        Mom:
          scoreFunction:
            function(a) 1/a$cost
        Kid:
          priority:
            - Beach: 1/2
            - Montañas: 0.5
      children: *alternatives
    Fön:
      preferences:
        Däd:
          pairwise:
            - [Beach, Montañas, 1/6]
        Mom:
          pairwise:
            - [Beach, Montañas, 2]
        Kid:
        # Often, entering pairwise preferences is lengthy, especially if you
        # have multiple alternatives. Instead, you can enter scores, i.e. rate
        # each alternative on a scale. The scale can be chosen freely. The 
        # priorities are derived as score / sum(scores)
          score:
            - Beach: 5
            - Montañas: 0
      children: *alternatives
    Spa:
      preferences:
        Däd:
          pairwise:
            - [Beach, Montañas, 2]
        Mom:
          pairwise:
            - [Beach, Montañas, 6]
        Kid:
          pairwise:
            - [Beach, Montañas, 1/2]
      children: *alternatives

Can you pls provide a reproducible example of what is not working for you? Ideally as a gist. Thx!

jjcizi commented 6 years ago

Thx for reply. but when I use the yaml code which you give above, still garbled. Däd, Montañas,etc. changed to garbled. But it is indeed normal , works, on the the online app at https://ipub.com/dev-corner/apps/ahp/. Why?

jjcizi commented 6 years ago

solved.

x <- readLines("file.yml")
x <- iconv(x,'UTF-8','UTF-8')
writeLines(x,"file.yml")

use icove() to change file to utf-8 ,then works.

thank you very much.