This repository has been archived by the owner on May 1, 2023. It is now read-only.
/
pas.go
75 lines (64 loc) · 1.44 KB
/
pas.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package jk
import (
"errors"
"strconv"
"strings"
)
//Argument represent a single argument
type Argument struct {
Sid string `json:"sid"`
Tid int `json:"tid"`
Rep string `json:"rep"`
}
// Arguments is a slice of Argument
type Arguments []Argument
//ArgMap is a map from string to Arguments
type ArgMap map[string]Arguments
// Pas represents a predicate argument structure
type Pas struct {
Cfid string
Args ArgMap
}
// NewPas returns a Pas
func NewPas(line string, knpstyle bool) (*Pas, error) {
if !knpstyle {
return nil, errors.New("Not Implemented")
}
return parseKnpStylePas(line)
}
func parseKnpStylePas(val string) (*Pas, error) {
if strings.Count(val, ":") < 2 {
return nil, nil
}
pas := new(Pas)
pas.Args = ArgMap{}
c0 := strings.Index(val, ":")
c1 := c0 + 1 + strings.Index(val[c0+1:], ":")
pas.Cfid = val[:c0] + ":" + val[c0+1:c1]
ks := strings.Split(val[c1+1:], ";")
for _, k := range ks {
items := strings.Split(k, "/")
casetype := items[1]
if casetype == "U" || casetype == "-" {
continue
}
if len(items) != 6 {
return nil, errors.New("Invalid number of values")
}
mycase := items[0]
rep := items[2]
tid, err := strconv.Atoi(items[3])
if err != nil {
return nil, err
}
sid := items[5]
arg := Argument{Sid: sid, Tid: tid, Rep: rep}
as, ok := pas.Args[mycase]
if !ok {
as = Arguments{}
pas.Args[mycase] = as
}
pas.Args[mycase] = append(pas.Args[mycase], arg)
}
return pas, nil
}