Skip to content

Commit

Permalink
Merge pull request #105 from hcmlab/develop
Browse files Browse the repository at this point in the history
Database  fixes, backward compatibility
  • Loading branch information
tobiasbaur authored Dec 19, 2016
2 parents 5300c94 + 0141bcf commit e73e005
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 205 deletions.
Binary file modified bin/nova.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions dll/AnnoList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public static AnnoList LoadfromFile(String filepath, double samplerate = 1, stri
}
else
{
AnnoListItem e = new AnnoListItem(start, samplerate, label, "", tier);
AnnoListItem e = new AnnoListItem(start, samplerate, label, "", "#000000", 1);
if (filter == null || tier == filter)
list.AddSorted(e);
}
Expand Down Expand Up @@ -385,7 +385,7 @@ public static AnnoList LoadfromFile(String filepath, double samplerate = 1, stri
{
label += " " + data[i];
}
AnnoListItem e = new AnnoListItem(start, duration, label, "", tier);
AnnoListItem e = new AnnoListItem(start, duration, label, "", "#000000", 1);
if (filter == null || tier == filter)
list.AddSorted(e);
}
Expand Down
2 changes: 1 addition & 1 deletion dll/AnnoTrackSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public AnnoTrackSegment(AnnoListItem item, AnnoTrack track)
this.Inlines.Add(item.Label);
this.FontSize = 12;
this.TextWrapping = TextWrapping.Wrap;
this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom(item.Bg));
if(item.Bg != "" && item.Bg != null) this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom(item.Bg));
this.Foreground = Brushes.White;
this.Opacity = 0.75;

Expand Down
44 changes: 37 additions & 7 deletions dll/Database/DatabaseCMLCompleteTierWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ssi"
Title="Complete Tier"
Height="400" Width="300" WindowStyle="ToolWindow">
Height="400" Width="500">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>


<Label Grid.Row="0"
Grid.Column="0"
Expand Down Expand Up @@ -46,7 +48,7 @@
<ListBox Name="StreamListBox"
Grid.Row="2"
Grid.Column="1"
SelectionMode="Single"
SelectionMode="Single" SelectionChanged="StreamListBox_SelectionChanged"
Margin="5"></ListBox>
<StackPanel Grid.Row="3" Grid.ColumnSpan="2">

Expand Down Expand Up @@ -109,6 +111,34 @@
Margin="5"
Click="FinishedButton_Click">Finished</Button>
</StackPanel>

<GridSplitter ResizeDirection="Columns"
Grid.Row="0"
Grid.RowSpan="9"
Grid.Column="4"
Grid.ColumnSpan="1"
Height="Auto"
Width="3"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="0">
</GridSplitter>

<TextBox Name="logTextBox"
Grid.Row="0"
Grid.RowSpan="4"
Grid.Column="3"
Margin="5"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" FontFamily="Consolas"
>
</TextBox>

<Button Name="CopyButton"
Grid.Row="5"
Grid.Column="3"
Margin="5"
HorizontalAlignment="Right"
Width="50"
Click="CopyButton_Click">Copy</Button>
</Grid>
</Window>
139 changes: 41 additions & 98 deletions dll/Database/DatabaseCMLCompleteTierWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DatabaseCMLCompleteTierWindow(ViewHandler handler)

foreach (AnnoTrack tier in handler.AnnoTracks)
{
if (tier.AnnoList.FromDB && tier.AnnoList.AnnotationScheme.name == "voiceactivity")
// if (tier.AnnoList.FromDB && tier.AnnoList.AnnotationScheme.name == "voiceactivity")
{

TierListBox.Items.Add(tier.AnnoList.Name);
Expand All @@ -36,6 +36,10 @@ public DatabaseCMLCompleteTierWindow(ViewHandler handler)
ConfidenceCheckBox.IsChecked = Properties.Settings.Default.CMLSetConf;
FillGapCheckBox.IsChecked = Properties.Settings.Default.CMLFill;
RemoveLabelCheckBox.IsChecked = Properties.Settings.Default.CMLRemove;

ConfidenceTextBox.Text = Properties.Settings.Default.CMLDefaultConf.ToString();
FillGapTextBox.Text = Properties.Settings.Default.CMLDefaultGap.ToString();
RemoveLabelTextBox.Text = Properties.Settings.Default.CMLDefaultMinDur.ToString();
}

private void ApplyButton_Click(object sender, RoutedEventArgs e)
Expand All @@ -55,7 +59,30 @@ private void ApplyButton_Click(object sender, RoutedEventArgs e)
{
DatabaseHandler db = new DatabaseHandler("mongodb://" + Properties.Settings.Default.MongoDBUser + ":" + Properties.Settings.Default.MongoDBPass + "@" + Properties.Settings.Default.MongoDBIP);
db.StoreToDatabase(Properties.Settings.Default.Database, Properties.Settings.Default.LastSessionId, Properties.Settings.Default.MongoDBUser, tier, handler.loadedDBmedia, false);
completeTier(context, tier, stream);

double confidence = -1.0;
if (ConfidenceTextBox.IsEnabled)
{
double.TryParse(ConfidenceTextBox.Text, out confidence);
}
double minGap = 0.0;
if (FillGapTextBox.IsEnabled)
{
double.TryParse(FillGapTextBox.Text, out minGap);
}
double minDur = 0.0;
if (RemoveLabelTextBox.IsEnabled)
{
double.TryParse(RemoveLabelTextBox.Text, out minDur);
}
Properties.Settings.Default.CMLDefaultGap = minGap;
Properties.Settings.Default.CMLDefaultConf = confidence;
Properties.Settings.Default.CMLDefaultMinDur = minDur;
Properties.Settings.Default.Save();

logTextBox.Text = "";
logTextBox.AppendText(handler.completeTier(context, tier, stream, confidence, minGap, minDur));
//logTextBox.AppendText(File.ReadAllText("cml.log"));
}
}
}
Expand All @@ -65,105 +92,10 @@ private void ApplyButton_Click(object sender, RoutedEventArgs e)

private void FinishedButton_Click(object sender, RoutedEventArgs e)
{

Close();
}

private void completeTier(int context, AnnoTrack tier, string stream)
{
Directory.CreateDirectory(Properties.Settings.Default.DataPath + "\\" + Properties.Settings.Default.Database + "\\models");

string username = Properties.Settings.Default.MongoDBUser;
string password = Properties.Settings.Default.MongoDBPass;
string session = Properties.Settings.Default.LastSessionId;
string datapath = Properties.Settings.Default.DataPath;
string ipport = Properties.Settings.Default.MongoDBIP;
string[] split = ipport.Split(':');
string ip = split[0];
string port = split[1];
string database = Properties.Settings.Default.Database;
string role = tier.AnnoList.Role;
string scheme = tier.AnnoList.AnnotationScheme.name;
string annotator = tier.AnnoList.Annotator;
double confidence = -1.0;
if (ConfidenceTextBox.IsEnabled)
{
double.TryParse(ConfidenceTextBox.Text, out confidence);
}
double minGap = 0.0;
if (FillGapTextBox.IsEnabled)
{
double.TryParse(FillGapTextBox.Text, out minGap);
}
double minDur = 0.0;
if (RemoveLabelTextBox.IsEnabled)
{
double.TryParse(RemoveLabelTextBox.Text, out minDur);
}

bool isTrained = false;
bool isForward = false;

string arguments = " -cooperative "
+ "-context " + context +
" -username " + username +
" -password " + password +
" -filter " + session +
" -confidence " + confidence +
" -mingap " + minGap +
" -mindur " + minDur +
" -log cml.log " +
"\"" + datapath + "\\" + database + "\" " +
ip + " " +
port + " " +
database + " " +
role + " " +
scheme + " " +
annotator + " " +
"\"" + stream + "\"";

{
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
// startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmltrain.exe";
startInfo.Arguments = "--train" + arguments;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
if (process.ExitCode == 0)
{
isTrained = true;
}
else
{
return;
}
}

{
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
// startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmltrain.exe";
startInfo.Arguments = "--forward" + arguments;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
if (process.ExitCode == 0)
{
isForward = true;
}
else
{
return;
}
}

if (isTrained && isForward)
{
handler.reloadAnnoDB(tier);
}
}

private void ConfidenceCheckBox_Checked(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -206,5 +138,16 @@ private void RemoveLabelCheckBox_Unchecked(object sender, RoutedEventArgs e)
Properties.Settings.Default.Save();
RemoveLabelTextBox.IsEnabled = false;
}

private void StreamListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
Properties.Settings.Default.CMLDefaultStream = StreamListBox.SelectedItem.ToString() ;
Properties.Settings.Default.Save();
}

private void CopyButton_Click(object sender, RoutedEventArgs e)
{
Clipboard.SetText(logTextBox.Text);
}
}
}
26 changes: 26 additions & 0 deletions dll/Database/DatabaseCMLTrainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public DatabaseCMLTrainWindow(ViewHandler handler)
FillGapCheckBox.IsChecked = Properties.Settings.Default.CMLFill;
RemoveLabelCheckBox.IsChecked = Properties.Settings.Default.CMLRemove;

ConfidenceTextBox.Text = Properties.Settings.Default.CMLDefaultConf.ToString();
FillGapTextBox.Text = Properties.Settings.Default.CMLDefaultGap.ToString();
RemoveLabelTextBox.Text = Properties.Settings.Default.CMLDefaultMinDur.ToString();



string[] roles = Properties.Settings.Default.CMLDefaultRoles.Split(';');
for(int i=0; i< roles.Length;i++)
{
Expand Down Expand Up @@ -242,8 +248,11 @@ private void ExtractButton_Click(object sender, RoutedEventArgs e)
{
if (TierListBox.SelectedItem != null && StreamListBox.SelectedItem != null)
{

process(true, false, false);

}

}

private void TrainButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -323,8 +332,17 @@ private void process(bool extract, bool train, bool forward)
{
double.TryParse(RemoveLabelTextBox.Text, out minDur);
}
Properties.Settings.Default.CMLDefaultGap = minGap;
Properties.Settings.Default.CMLDefaultConf = confidence;
Properties.Settings.Default.CMLDefaultMinDur = minDur;
Properties.Settings.Default.Save();


logTextBox.Text = "";
try
{



if (extract)
//EXTRACT MISSING FEATURES
Expand Down Expand Up @@ -442,7 +460,15 @@ private void process(bool extract, bool train, bool forward)
return;
}
logTextBox.AppendText(File.ReadAllText("cml.log"));

}
}

catch
{
MessageBox.Show("Cooperative Machine Learning System not found. This will be integrated in the public release soon.");
}

}

private void TierListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down
15 changes: 14 additions & 1 deletion dll/Database/DatabaseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,12 @@ public string StoreToDatabase(string db, string session, string dbuser, AnnoTrac
UpdateOptions uo = new UpdateOptions();
uo.IsUpsert = true;

var checklock = annotations.Find(filter2).Single();


bool islocked = false;
try
{
var checklock = annotations.Find(filter2).Single();
islocked = checklock["isLocked"].AsBoolean;

}
Expand All @@ -484,6 +485,13 @@ public string StoreToDatabase(string db, string session, string dbuser, AnnoTrac
return annotator;
}

public IMongoDatabase GetDatabase()
{
return database;
}



public List<AnnoList> LoadFromDatabase(System.Collections.IList collections, string db, string session, string dbuser)
{
mongo = new MongoClient(connectionstring);
Expand Down Expand Up @@ -651,6 +659,11 @@ public List<AnnoList> LoadFromDatabase(System.Collections.IList collections, str
return l;
}






public string FetchDBRef(IMongoDatabase database, string collection, string attribute, ObjectId reference)
{
string output = "";
Expand Down
Loading

0 comments on commit e73e005

Please sign in to comment.