# NPSBridge

Implements \NPS\DependencyInjection\IExpertSystemBridge, \NPS\DependencyInjection\IKnowledgeBaseInfoProvider

Handles communication with an external NPS process

author | Lukas Korinek
package | Default

### Methods

## __construct

    __construct(\Psr\Log\LoggerInterface $npsLogger, \Symfony\Component\HttpFoundation\RequestStack $requestStack, string $npsPath)

### Arguments

#### $npsLogger

`\Psr\Log\LoggerInterface`

#### $requestStack

`\Symfony\Component\HttpFoundation\RequestStack`

#### $npsPath

`string`

Path to the NPS application executable

## Destruct the process also

    __destruct()

## Rewinds the consultation back by one question

    back() : boolean

inheritDoc |

### Response

`boolean`

## Gets hypothesis

    baseGetHypothesis(\NPS\Model\TraversableXMLElement &$output = null) : boolean

### Arguments

#### $output

`\NPS\Model\TraversableXMLElement`

### Response

`boolean`

## Gets info

    baseGetInfo(\NPS\Model\TraversableXMLElement &$output = null) : boolean

### Arguments

#### $output

`\NPS\Model\TraversableXMLElement`

### Response

`boolean`

## Gets current language and lists supported ones

    baseGetLanguage(\NPS\Model\TraversableXMLElement &$output = null) : boolean

### Arguments

#### $output

`\NPS\Model\TraversableXMLElement`

### Response

`boolean`

## Gets the current query

    baseGetQuery(\NPS\Model\TraversableXMLElement &$output = null) : boolean

### Arguments

#### $output

`\NPS\Model\TraversableXMLElement`

### Response

`boolean`

## Gets consultation state structure

    baseGetState(boolean $direct = false, string &$state = null) : boolean

### Arguments

#### $direct

`boolean`

Whether to return or store in a file

#### $state

`string`

Path to the file or a data structure in which to store the data

### Response

`boolean`

## Continues forward in the consultation

    baseGoAhead() : boolean

### Response

`boolean`

## Goes back in the consultation

    baseGoBack() : boolean

### Response

`boolean`

## Resets whole consultation

    baseResetBase() : boolean

### Response

`boolean`

## Resets current query and all backed queries

    baseResetQuery() : boolean

### Response

`boolean`

## Sets the answer of a query

    baseSetAnswer(mixed $answerId) : boolean

### Arguments

#### $answerId

`mixed`

### Response

`boolean`

## Sets the language of the base

    baseSetLanguage(mixed $langId) : boolean

### Arguments

#### $langId

`mixed`

### Response

`boolean`

## Sets the consultation state

    baseSetState(boolean $direct = false, string|\NPS\Model\TraversableXMLElement $state) : boolean

### Arguments

#### $direct

`boolean`

Whether to restore from a file or a state structure

#### $state

`string|\NPS\Model\TraversableXMLElement`

Either state XML structure or path to a file

### Response

`boolean`

## Closes an active knowledge base

    cmdCloseBase() : boolean

### Response

`boolean`

## Converts a knowledge base from old format to new format

    cmdConvertBase(string $source, string $destination) : boolean

### Arguments

#### $source

`string`

Source file to convert

#### $destination

`string`

Destination file to convert

### Response

`boolean`

## Closes the NPS application

    cmdExit() : boolean

### Response

`boolean`

## Loads a knowledge base

    cmdLoadBase(string $path) : boolean

### Arguments

#### $path

`string`

Path to the knowledge base file

### Response

`boolean`

## Executes a command on an NPS instance

    command(\NPS\Model\TraversableXMLElement $commandElement, \NPS\Model\TraversableXMLElement &$output = null) : boolean

### Arguments

#### $commandElement

`\NPS\Model\TraversableXMLElement`

Element with the command

#### $output

`\NPS\Model\TraversableXMLElement`

Element to which to store the output

### Response

`boolean`

## Converts between old and new base formats

    convertBaseFormat(string $source, string $destination) : boolean

### Arguments

#### $source

`string`

Base to convert, absolute path

#### $destination

`string`

Destination file

### Response

`boolean`

## Creates the asynchronous process which will run NPSCore

    createProcess() :

Throws | \Symfony\Component\Process\Exception\RuntimeException

### Response

``

## Ends the current consultation

    endConsultation() : boolean

inheritDoc |

### Response

`boolean`

## Forces the NPS process to be terminated at all costs

    forceProcessTermination() : boolean

static

### Response

`boolean`

True on successful termination

## Shifts the consultation to go forward by one question (answered)

    forward() : boolean

inheritDoc |

### Response

`boolean`

## Gets default language of the provider

    getDefaultLanguage() : string

inheritDoc |

### Response

`string`

Language short (non ISO) string

## Gets hypothesis for the consultation and their rank

    getHypothesis() : array|null

inheritDoc |

### Response

`array|null`

Array of hypothesis content elements, null on failure

## Gets a knowledge base description by its file path

    getKnowledgeBaseDescription(string $path) : string

inheritDoc |

### Arguments

#### $path

`string`

### Response

`string`

## Gets languages supported by a knowledge base

    getKnowledgeBaseLanguages(string $path) : array

inheritDoc |

### Arguments

#### $path

`string`

### Response

`array`

## Gets a knowledge base name by its file path

    getKnowledgeBaseName(string $path) : string

inheritDoc |

### Arguments

#### $path

`string`

### Response

`string`

## Gets the language which is currently set for the consultation

    getLanguage() : string

inheritDoc |

### Response

`string`

null on failure

## Gets next question

    getQuestion() : \NPS\Model\TraversableXMLElement|null

inheritDoc |

### Response

`\NPS\Model\TraversableXMLElement|null`

Element with question details, null on failure

## Gets all the supported languages of this base

    getSupportedLanguages() : array

inheritDoc |

### Response

`array`

## Determines if the consultation has ended

    isEnded() : boolean|null

inheritDoc |

### Response

`boolean|null`

Null on failure

## Loads the knowledge base if necessary

    loadBase(string $path) : boolean

### Arguments

#### $path

`string`

### Response

`boolean`

## Loads a consultation from stored state

    loadConsultationState(array $data) : boolean

inheritDoc |

### Arguments

#### $data

`array`

### Response

`boolean`

True on success

## logMessages

    logMessages()

inherited

inheritDoc |

## popMessage

    popMessage()

inherited

inheritDoc |

## Pushes a message

    pushMessage(string $message)

inherited

### Arguments

#### $message

`string`

## Saves the consultation and returns consultation data

    saveConsultationState() : array

inheritDoc |

### Response

`array`

with keys "base", "started", "language", "internal"

## Sets answer to the current question

    setAnswer(mixed $answer) : boolean

inheritDoc |

### Arguments

#### $answer

`mixed`

### Response

`boolean`

## Sets default language of the provider

    setDefaultLanguage(string $language)

inheritDoc |

### Arguments

#### $language

`string`

Language short (non ISO) string

## Sets the language of the consultation

    setLanguage(string $language) : boolean|null

inheritDoc |

### Arguments

#### $language

`string`

One of the languages

### Response

`boolean|null`

Null for an unsupported language. False for command fail

## Starts a consultation

    startConsultation(string $path) : boolean

inheritDoc |

### Arguments

#### $path

`string`

Knowledge base path

### Response

`boolean`

True on success

## Terminates the NPS process

    terminateProcess()

### Properties

## Handle to the NPS process

    process : \Symfony\Component\Process\Process

static

var | Handle to the NPS process

### Type(s)

`\Symfony\Component\Process\Process`

## Input stream for the asynchronous process

    processInput : \Symfony\Component\Process\InputStream

static

var | Input stream for the asynchronous process

### Type(s)

`\Symfony\Component\Process\InputStream`

## Path to the executable of NPS

    path : string

var | Path to the executable of NPS

### Type(s)

`string`

## logger

    logger : \Psr\Log\LoggerInterface

var |

### Type(s)

`\Psr\Log\LoggerInterface`

## defaultLanguage

    defaultLanguage : string

var |

### Type(s)

`string`

## currentBasePath

    currentBasePath : string

var |

### Type(s)

`string`

## currentSupportedLanguages

    currentSupportedLanguages : array

var |

### Type(s)

`array`

## currentLanguage

    currentLanguage : string

var |

### Type(s)

`string`

## messages

    messages : array

inherited

var |

### Type(s)

`array`

## messagePointer

    messagePointer : integer

inherited

var |

### Type(s)

`integer`