Skip to content

WPS Partnership API V2

Update TimeNotes
Dec 13, 15:00Added xclozeType and xchunkType descriptions for the tip endpoint
Dec 18, 17:00Updated error category localization and suggestions
Dec 25, 14:00Added combined endpoint; errors now support one-to-many cands
Dec 25, 16:00Added xconfusion description in tip

1. Overview

Authentication

IP whitelist is used for authentication.

shell
curl --request POST \
  --url https://url_cn/api \
  -H "Content-Type: application/json" \
  --data '{"json":"data"}'
curl --request POST \
  --url https://url_cn/api \
  -H "Content-Type: application/json" \
  --data '{"json":"data"}'

Conventions

  • IP whitelist authentication
  • Submit JSON data in the request body
  • Responses are also in JSON format

Flow

  1. Split article into sentences
  2. After splitting, errors, warnings, and tips can be fetched in parallel

Environments

url_cn entry points:

DomainTypeDescription
http://wps.pigai.org:8756stringProduction environment

2. Sentence Splitting Endpoint

Endpoint: POST https://url_cn/wpsv2-xtext

Request:

json
{
    "text": "She has ready.\nI pay attention to the box. This are gramamtical sentence."
}
{
    "text": "She has ready.\nI pay attention to the box. This are gramamtical sentence."
}
FieldTypeRequiredDescription
textstringYesInput text

Response:

json
{
    "snts": [
        "She has ready.",
        "\nI pay attention to the box.",
        "This are gramamtical sentence."
    ],
    "offsets": [0, 14, 43]
}
{
    "snts": [
        "She has ready.",
        "\nI pay attention to the box.",
        "This are gramamtical sentence."
    ],
    "offsets": [0, 14, 43]
}
FieldTypeRequiredDescription
sntsstring[]YesSentences after splitting
offsetsnumber[]NoCharacter offsets of each sentence

3. Error Endpoint

Endpoint: POST https://url_cn/wpsv2-err

Request:

json
{
    "snts": [
        "She has ready.\n",
        "I pay attention to the box.",
        "This are gramamtical sentence."
    ]
}
{
    "snts": [
        "She has ready.\n",
        "I pay attention to the box.",
        "This are gramamtical sentence."
    ]
}
FieldTypeRequiredDescription
sntsstring[]YesSentences after splitting

Response:

json
{
    "data": [
        {
            "snt": "She has ready.\n",
            "edits": [
                {
                    "offset": 4,
                    "itok": 1,
                    "orig": "has",
                    "corr": "is",
                    "type": "R",
                    "cate": "VERB"
                }
            ],
            "toks": [
                { "i": 0, "offset": 0, "textws": "She " },
                { "i": 1, "offset": 4, "textws": "has " },
                { "i": 2, "offset": 8, "textws": "ready" },
                { "i": 3, "offset": 13, "textws": "." },
                { "i": 4, "offset": 14, "textws": "\n" }
            ]
        },
        {}
    ],
    "total": 4
}
{
    "data": [
        {
            "snt": "She has ready.\n",
            "edits": [
                {
                    "offset": 4,
                    "itok": 1,
                    "orig": "has",
                    "corr": "is",
                    "type": "R",
                    "cate": "VERB"
                }
            ],
            "toks": [
                { "i": 0, "offset": 0, "textws": "She " },
                { "i": 1, "offset": 4, "textws": "has " },
                { "i": 2, "offset": 8, "textws": "ready" },
                { "i": 3, "offset": 13, "textws": "." },
                { "i": 4, "offset": 14, "textws": "\n" }
            ]
        },
        {}
    ],
    "total": 4
}
FieldTypeRequiredDescription
dataobject[]YesPer-sentence data objects
totalnumberYesTotal error count
  • Each object in data contains one sentence's results
  • edits[i].itok is the token index in toks, enabling replacement
FieldTypeRequiredDescription
sntstringYesSentence text
editsobject[]YesCorrection suggestions
edits[i].offsetnumberYesCharacter offset in sentence
edits[i].itoknumberYesToken index in toks
edits[i].origstringYesOriginal token
edits[i].corrstringYesCorrected token
edits[i].typeR,M,UYesR=replace, M=insert, U=delete
edits[i].catestringYesError category
edits[i].ofstringNoLocalized error category
edits[i].shortmsgstringYesSuggestion
toksobject[]YesToken positions
toks[i].inumberYesToken index in sentence
toks[i].offsetnumberNoCharacter position in sentence
toks[i].textwsstringYesToken with trailing space
ts
export interface editType {  
    "offset": number
    "itok": number        // start position in toks
    "iend": number        // end position (exclusive) in toks
    "orig": string
    "corr": string
    "type": "R"|"M"|"U"  // R=replace, M=insert, U=delete
    "cate": string
    "of"?: string         // localized category
    "shortmsg": string    // suggestion
    isModify?: boolean    // whether modified — add this field yourself
    cands?: string[]      // replacement candidates when there are many options
    context?: any[]       // replacement context; indices 0|1 are number, 2 is string
}
export interface editType {  
    "offset": number
    "itok": number        // start position in toks
    "iend": number        // end position (exclusive) in toks
    "orig": string
    "corr": string
    "type": "R"|"M"|"U"  // R=replace, M=insert, U=delete
    "cate": string
    "of"?: string         // localized category
    "shortmsg": string    // suggestion
    isModify?: boolean    // whether modified — add this field yourself
    cands?: string[]      // replacement candidates when there are many options
    context?: any[]       // replacement context; indices 0|1 are number, 2 is string
}

4. Warning Endpoint

  • Endpoint: POST https://url_cn/wpsv2-warn
  • URL names accepts two values: xsntwarn and xsntflue, comma-separated: names=urlencode(xsntwarn,xsntflue)
  • Additional types may be added to names in the future; omitting it uses defaults

Request:

json
{
    "snts": [
        "She has ready.\n",
        "I pay attention to the box.",
        "This are gramamtical sentence."
    ]
}
{
    "snts": [
        "She has ready.\n",
        "I pay attention to the box.",
        "This are gramamtical sentence."
    ]
}
FieldTypeRequiredDescription
sntsstring[]YesSentences after splitting

Response:

json
{
  "total": 5,
  "items": {
    "xsntwarn": 2,
    "xsntflue": 3
  },
  "data": {
    "xsntwarn": [
      [],
      [
        {
          "type": "NP",
          "offset": 6,
          "wordlist": "a big boxe",
          "shortmsg": "<b>a big boxe</b> is rarely used by native speakers",
          "by": "gramoov"
        }
      ],
      [
        {
          "type": "word",
          "pos": "NOUN",
          "ibeg": 2,
          "offset": 7,
          "wordlist": "traffics",
          "shortmsg": "<b>traffics</b> is not normally used in plural form",
          "by": "noun_noplual"
        }
      ]
    ],
    "xsntflue": [
      [
        {
          "type": "sent",
          "snt": "She has ready.",
          "flue": 0.056,
          "by": "xsntflue",
          "shortmsg": "Please check the syntax of this sentence"
        }
      ],
      [
        {
          "type": "sent",
          "snt": "It is a big boxe.",
          "flue": 0.4247,
          "by": "xsntflue",
          "shortmsg": "Please check the syntax of this sentence"
        }
      ],
      [
        {
          "type": "sent",
          "snt": "It are traffics.",
          "flue": 0.0425,
          "by": "xsntflue",
          "shortmsg": "Please check the syntax of this sentence"
        }
      ]
    ]
  }
}
{
  "total": 5,
  "items": {
    "xsntwarn": 2,
    "xsntflue": 3
  },
  "data": {
    "xsntwarn": [
      [],
      [
        {
          "type": "NP",
          "offset": 6,
          "wordlist": "a big boxe",
          "shortmsg": "<b>a big boxe</b> is rarely used by native speakers",
          "by": "gramoov"
        }
      ],
      [
        {
          "type": "word",
          "pos": "NOUN",
          "ibeg": 2,
          "offset": 7,
          "wordlist": "traffics",
          "shortmsg": "<b>traffics</b> is not normally used in plural form",
          "by": "noun_noplual"
        }
      ]
    ],
    "xsntflue": [
      [
        {
          "type": "sent",
          "snt": "She has ready.",
          "flue": 0.056,
          "by": "xsntflue",
          "shortmsg": "Please check the syntax of this sentence"
        }
      ],
      [
        {
          "type": "sent",
          "snt": "It is a big boxe.",
          "flue": 0.4247,
          "by": "xsntflue",
          "shortmsg": "Please check the syntax of this sentence"
        }
      ],
      [
        {
          "type": "sent",
          "snt": "It are traffics.",
          "flue": 0.0425,
          "by": "xsntflue",
          "shortmsg": "Please check the syntax of this sentence"
        }
      ]
    ]
  }
}
FieldTypeRequiredDescription
totalnumberYesTotal warning count
itemsobjectNoPer-category counts
dataobjectYesWarning data
  • data.xsntwarn — sentence-level warnings; data.xsntflue — fluency warnings
  • Both are arrays of arrays, one per sentence
ts
interface xsntwarnType {
    "type": string
    "offset"?: number
    "wordlist": string    // matched word or phrase
    "shortmsg": string    // tip message
    "by": string          // engine module name
}
interface xsntwarnType {
    "type": string
    "offset"?: number
    "wordlist": string    // matched word or phrase
    "shortmsg": string    // tip message
    "by": string          // engine module name
}
ts
interface xsntflueType {
    "type": string
    "snt": string         // sentence
    "flue": number        // fluency score
    "by"?: string         // engine module name
    "shortmsg": string    // suggestion
}
interface xsntflueType {
    "type": string
    "snt": string         // sentence
    "flue": number        // fluency score
    "by"?: string         // engine module name
    "shortmsg": string    // suggestion
}

5. Tip Endpoint

  • Endpoint: POST https://url_cn/wpsv2-tip
  • URL names accepts two values: xcloze and xchunk, comma-separated: names=urlencode(xcloze,xchunk)
  • Additional types may be added in the future; omitting uses defaults

Request:

json
{
  "snts": [
    "I am too tired to move on.",
    "I pay attention to the box."
  ],
  "topk": 10
}
{
  "snts": [
    "I am too tired to move on.",
    "I pay attention to the box."
  ],
  "topk": 10
}
FieldTypeRequiredDescription
sntsstring[]YesSentences after splitting
topknumberNoNumber of tip suggestions

Response:

json
{
  "total": 4,
  "items": {
    "xcloze": 2,
    "xchunk": 2
  },
  "data": {
    "xcloze": [
      [
        {
          "word": "tired",
          "sentiment": 0,
          "cands": [
            ["weak", 0.0283, 0.2589],
            ["hungry", 0.0134, 0.4132]
          ]
        }
      ],
      [
        {
          "word": "box",
          "sentiment": 0,
          "cands": [
            ["clock", 0.0438, 0.0791],
            ["surroundings", 0.0142, 0.0502],
            ["noise", 0.0135, 0.0323],
            []
          ]
        }
      ]
    ],
    "xchunk": [
      [],
      [
        {
          "ibeg": 1,
          "iend": 4,
          "tag": "_jj",
          "offset": 1,
          "pattern": "pay _jj attention to",
          "cands": [
            ["close", "195392"],
            ["particular", "159440"],
            []
          ]
        },
        {
          "ibeg": 4,
          "iend": 6,
          "tag": "_jj",
          "offset": 1,
          "pattern": "the _jj box",
          "cands": [
            ["appropriate", "250394"],
            ["original", "167511"]
          ]
        }
      ]
    ]
  }
}
{
  "total": 4,
  "items": {
    "xcloze": 2,
    "xchunk": 2
  },
  "data": {
    "xcloze": [
      [
        {
          "word": "tired",
          "sentiment": 0,
          "cands": [
            ["weak", 0.0283, 0.2589],
            ["hungry", 0.0134, 0.4132]
          ]
        }
      ],
      [
        {
          "word": "box",
          "sentiment": 0,
          "cands": [
            ["clock", 0.0438, 0.0791],
            ["surroundings", 0.0142, 0.0502],
            ["noise", 0.0135, 0.0323],
            []
          ]
        }
      ]
    ],
    "xchunk": [
      [],
      [
        {
          "ibeg": 1,
          "iend": 4,
          "tag": "_jj",
          "offset": 1,
          "pattern": "pay _jj attention to",
          "cands": [
            ["close", "195392"],
            ["particular", "159440"],
            []
          ]
        },
        {
          "ibeg": 4,
          "iend": 6,
          "tag": "_jj",
          "offset": 1,
          "pattern": "the _jj box",
          "cands": [
            ["appropriate", "250394"],
            ["original", "167511"]
          ]
        }
      ]
    ]
  }
}
FieldTypeRequiredDescription
totalnumberYesTotal tip count
itemsobjectNoPer-category counts
dataobjectYesTip data
  • data.xcloze — synonym suggestions; data.xchunk — chunk-level suggestions; data.xconfusion — confusion word suggestions
  • Each is an array of arrays, one per sentence
ts
interface xclozeType {
    "word": string          // candidate replacement word
    "sentiment": -1|0|1     // -1=negative, 0=neutral, 1=positive
    "cands": any[][]        // [0]=candidate, [1]=sentence relevance, [2]=word distance
}
interface xclozeType {
    "word": string          // candidate replacement word
    "sentiment": -1|0|1     // -1=negative, 0=neutral, 1=positive
    "cands": any[][]        // [0]=candidate, [1]=sentence relevance, [2]=word distance
}
ts
interface xchunkType {
    "ibeg"?: number,
    "iend"?: number,
    "tag": string,          // replacement slot
    "offset": number,
    "pattern": string,      // chunk pattern
    "cands": string[][]     // take index [0] from each inner array
}
interface xchunkType {
    "ibeg"?: number,
    "iend"?: number,
    "tag": string,          // replacement slot
    "offset": number,
    "pattern": string,      // chunk pattern
    "cands": string[][]     // take index [0] from each inner array
}

6. Combined Error + Warning + Tip Endpoint

  • Endpoint: POST https://url_cn/wpsv2?timeout=6

6.1 Request

  • timeout — timeout in seconds, default 6s
json
{
  "snts": [
    "She has ready.",
    "Traffics is a big boxe."
  ] 
}
{
  "snts": [
    "She has ready.",
    "Traffics is a big boxe."
  ] 
}
FieldTypeRequiredDescription
sntsstring[]YesSentences after splitting

6.2 Response

json
{
    "snts": ["She has ready.", "Traffics is a big boxe."],
    "err": ["xsntedits"],
    "warn": ["xsntwarn", "xsntflue"],
    "tip": ["xcloze", "xchunk", "xconfusion"],
    "default": ["xsnttoks"],
    "items": {
        "xsnttoks": 10,
        "xsntedits": 3,
        "xsntwarn": 2,
        "xsntflue": 2,
        "xcloze": 1,
        "xchunk": 0,
        "xconfusion": 1
    },
    "xsnttoks": [[...], [...]],
    "xsntedits": [[...], [...]],
    "xsntwarn": [[], [...]],
    "xsntflue": [[...], [...]],
    "xcloze": [[], [...]],
    "xchunk": [[], []],
    "xconfusion": [[], [...]],
    "total": { "err": 3, "warn": 4, "tip": 2 },
    "time": {
        "xsnttoks": 0.0021,
        "xsntedits": 0.0017,
        "xsntwarn": 0.0046,
        "xsntflue": 0.0415,
        "xcloze": 0.0431,
        "xchunk": 0.0321,
        "xconfusion": 0.0028,
        "total": 0.05
    }
}
{
    "snts": ["She has ready.", "Traffics is a big boxe."],
    "err": ["xsntedits"],
    "warn": ["xsntwarn", "xsntflue"],
    "tip": ["xcloze", "xchunk", "xconfusion"],
    "default": ["xsnttoks"],
    "items": {
        "xsnttoks": 10,
        "xsntedits": 3,
        "xsntwarn": 2,
        "xsntflue": 2,
        "xcloze": 1,
        "xchunk": 0,
        "xconfusion": 1
    },
    "xsnttoks": [[...], [...]],
    "xsntedits": [[...], [...]],
    "xsntwarn": [[], [...]],
    "xsntflue": [[...], [...]],
    "xcloze": [[], [...]],
    "xchunk": [[], []],
    "xconfusion": [[], [...]],
    "total": { "err": 3, "warn": 4, "tip": 2 },
    "time": {
        "xsnttoks": 0.0021,
        "xsntedits": 0.0017,
        "xsntwarn": 0.0046,
        "xsntflue": 0.0415,
        "xcloze": 0.0431,
        "xchunk": 0.0321,
        "xconfusion": 0.0028,
        "total": 0.05
    }
}

6.3 Response Field Reference

FieldTypeDescription
errstring[]Error fields — may contain xsntedits
warnstring[]Warning fields — may contain xsntwarn, xsntflue
tipstring[]Tip fields — may contain xcloze, xchunk, xconfusion
totaltotalTypeTotals for err, warn, tip
itemsitemsTypePer-category counts
xsnttokstoksType[][]Tokenized data with spaces; outer index = sentence, inner = token
xsnteditseditType[][]Outer = sentence, inner = edit
xsntwarnxsntwarnType[][]Outer = sentence, inner = warning
xconfusionconfusionType[][]Outer = sentence, inner = confusion item
xsntflueflueType[][]Outer = sentence, inner = fluency item
xclozexclozeType[][]Outer = sentence, inner = cloze tip
xchunkxchunkType[][]Outer = sentence, inner = chunk tip
timetimeTypeTiming breakdown

Type Definitions

totalType

ts
interface totalType { 
    "err": number
    "warn": number
    "tip": number
}
interface totalType { 
    "err": number
    "warn": number
    "tip": number
}

itemsType

ts
interface itemsType {
    "xsnttoks": number
    "xsntedits": number
    "xsntwarn": number
    "xsntflue": number
    "xcloze": number
    "xchunk": number
    "xconfusion": number
}
interface itemsType {
    "xsnttoks": number
    "xsntedits": number
    "xsntwarn": number
    "xsntflue": number
    "xcloze": number
    "xchunk": number
    "xconfusion": number
}

toksType

ts
interface toksType { 
    "i": number       // token index in sentence
    "offset": number  // character position in sentence
    "textws": string  // token with trailing space
}
interface toksType { 
    "i": number       // token index in sentence
    "offset": number  // character position in sentence
    "textws": string  // token with trailing space
}

editType

ts
export interface editType {  
    "offset": number
    "itok": number
    "iend": number
    "orig": string
    "corr": string
    "type": "R"|"M"|"U"
    "cate": string
    "of"?: string
    "shortmsg": string
    isModify?: boolean
    cands?: string[]
    context?: any[]
}
export interface editType {  
    "offset": number
    "itok": number
    "iend": number
    "orig": string
    "corr": string
    "type": "R"|"M"|"U"
    "cate": string
    "of"?: string
    "shortmsg": string
    isModify?: boolean
    cands?: string[]
    context?: any[]
}

xclozeType

ts
interface xclozeType {
    "word": string
    "sentiment": -1|0|1
    "cands": any[][]
}
interface xclozeType {
    "word": string
    "sentiment": -1|0|1
    "cands": any[][]
}

xchunkType

ts
interface xchunkType {
    "ibeg"?: number,
    "iend"?: number,
    "tag": string,
    "offset": number,
    "pattern": string,
    "cands": string[][]
}
interface xchunkType {
    "ibeg"?: number,
    "iend"?: number,
    "tag": string,
    "offset": number,
    "pattern": string,
    "cands": string[][]
}

xsntwarnType

ts
interface xsntwarnType {
    "type": string
    "offset"?: number
    "wordlist": string
    "shortmsg": string
    "by": string
}
interface xsntwarnType {
    "type": string
    "offset"?: number
    "wordlist": string
    "shortmsg": string
    "by": string
}

flueType

ts
interface flueType {
    "type": string
    "snt": string
    "flue": number
    "by": string
}
interface flueType {
    "type": string
    "snt": string
    "flue": number
    "by": string
}

confusionType

ts
interface confusionType {
    "word": string
    "lemma": string
    "pos": string
    "ibeg": number
    "offset": number
    "of": string
    "cands": string[]
}
interface confusionType {
    "word": string
    "lemma": string
    "pos": string
    "ibeg": number
    "offset": number
    "of": string
    "cands": string[]
}

timeType

ts
interface timeType {
    "xsnttoks"?: number
    "xsntedits"?: number
    "xsntwarn"?: number
    "xsntflue"?: number
    "xcloze"?: number
    "xchunk"?: number
    "xconfusion"?: number
    "total": number
}
interface timeType {
    "xsnttoks"?: number
    "xsntedits"?: number
    "xsntwarn"?: number
    "xsntflue"?: number
    "xcloze"?: number
    "xchunk"?: number
    "xconfusion"?: number
    "total": number
}