Importing Entities
Oscova supports importing of multiple entities or entry values from CSV files or text values. Please note that the CSV data for import must not have a header specified.
Import Entities
To import entities from CSV files you can call the ImportEntitiesFromFile(filePath)
method and specify the path of the file to import that data from.
The format of the file should be <Entity-Name>, <Value>, <Synonyms>
as shown in the example data below. Both <Entity-Name>
and <Value>
are mandatory. However, Synonyms are optional.
Example 1 CSV
Size, Big, Large
Size, Medium, Med, Normal
Size, Small, Minimum, Min
Priority, High
Priority, Low, Ignore, Least
NOTE From version 5.0 you can now omit declaring entity type name if you've specified in any upper rows. See example below.
Example 2 CSV
Size, Big, Large
, Medium, Med, Normal
, Small, Minimum, Min
Priority, High
, Low, Ignore, Least
The above CSV File in Excel would like the following.
The content however internally will render exactly as Example 1 CSV
.
To import a file with the csv data as shown above. You can call the ImportEntitiesFromFile
method as shown below.
var oscovaBot = new OscovaBot();
oscovaBot.ImportEntitiesFromFile(@"c:\entities.csv", EntityDataFormat.Csv);
If you have the CSV data stored is any other location such as a database then you can call the ImportEntitiesFromText
method instead to tell Oscova to parse the value as a textual data.
var oscovaBot = new OscovaBot();
//Get the data from any other source.
var entityData = SomeUtility.FromDatabase("entities");
//Pass the string data.
oscovaBot.ImportEntitiesFromText(entityData, EntityDataFormat.Csv);
Import Entries to an Entity Type
You import entity specific data from CSV files by using the ImportFromFile
or ImportFromText
methods on the Entries
property of the newly created entity recognizer.
The format of the CSV data should be <Value>, <Synonyms>
. Where the <Synonyms>
part is optional.
Example CSV
Big, Large,
Medium, Med, Normal
Small
To import the above mentioned CSV data from a file, call the ImportFromFile
method on the Entries
collection as shown below.
var oscovaBot = new OscovaBot();
var sizeRecognizer = oscovaBot.CreateRecognizer("size");
sizeRecognizer.Entries.ImportFromFile(@"c:\entities\size.csv", EntityDataFormat.Csv);
To import the above CSV data from any other source such a database you can utilize the ImportFromText
method and provide the textual value of the csv data.
var oscovaBot = new OscovaBot();
var sizeRecognizer = oscovaBot.CreateRecognizer("size");
//Get the data from any other source.
var entriesData = SomeUtility.FromDatabase("size-entity");
//Pass the string data.
sizeRecognizer.Entries.ImportFromText(entriesData, EntityDataFormat.Csv);