for (int i = 0; i < table1.Rows.Count; i++) { textBoxList[i].Click += new EventHandler(this.iri_Click); labelList[i].Location = new Point(10, i * 22 + 50); textBoxList[i].Location = new Point(150, i * 22 + 50); describeForm.Controls.Add(labelList[i]); describeForm.Controls.Add(textBoxList[i]);
for (int i = 0; i < table1.Rows.Count; i++) { textBoxList[i].Click += new EventHandler(this.iri_Click); labelList[i].Location = new Point(10, i * 22 + 50); labelList[i].Click += new EventHandler(this.label_Click); textBoxList[i].Location = new Point(150, i * 22 + 50); describeForm.Controls.Add(labelList[i]); describeForm.Controls.Add(textBoxList[i]);
public void label_Click(object sender, EventArgs e) { int labelNum = 0; for (int i = 0; i < labelList.Count; i++) { if (sender == labelList[i]) { labelNum = i; break; } } Object o = describeDataSet.DataTable1.Rows[labelNum][0]; if (o is SqlExtendedString) { SqlExtendedString se = (SqlExtendedString)o; ExtendedStringHandler seHandler = new ExtendedStringHandler(se, ParentConnection); seHandler.displayData(); } else if (o is SqlRdfBox) { //doesn't do anything at the moment } }
propertyLabel.Text = getLabelText(row[0]); propertyLabel.AutoEllipsis = true; propertyLabel.AutoSize = false; propertyLabel.Width = 130; propertyLabel.TextAlign = ContentAlignment.MiddleRight;
propertyLabel.Text = getLabelText(row[0]); propertyLabel.ForeColor = Color.Blue; propertyLabel.Font = new Font(propertyLabel.Font.FontFamily, propertyLabel.Font.Size, propertyLabel.Font.Style | FontStyle.Underline, propertyLabel.Font.Unit); propertyLabel.AutoEllipsis = true; propertyLabel.AutoSize = false; propertyLabel.Width = 130; propertyLabel.TextAlign = ContentAlignment.MiddleRight;
These simple changes work up to a point but are not robust. If you explore the properties used by the local Northwind graph you quickly find that the property details are not found. The application needs some further changes to work consistently. The problem is finding the graph where the property information is defined. The general handler for Extended Strings first checks the local Northwind graph, http://localhost:8890/Northwind, where the Northwind data is held, and then uses the IRI itself as the graph and tries to load that dynamically. This is not working for information about the Northwind properties. These properties are defined in the Northwind ontology, http://demo.openlinksw.com/schemas/northwind. We have already had to find this graph when getting the short label name. We need to be able to associate the property label with the graph where its definition is stored. Then we can search this graph for details about the property when the label is clicked.
using System.Windows.Forms; using OpenLink.Data.Virtuoso; using System.Data;
class IRILabel : Label
SqlExtendedString SourceIRI; String GraphUsed; VirtuosoConnection ParentConnection; public IRILabel(Object iri, List<String> graphList, VirtuosoConnection parentConnection) { ParentConnection = parentConnection; if (iri is SqlExtendedString) { SourceIRI = (SqlExtendedString)iri; Text = this.getLabelText(graphList); } else Text = iri.ToString(); } public SqlExtendedString iri { get { return SourceIRI; } } public String graph { get { return GraphUsed; } } private string getLabelText(List<String> graphList) { string labelText = SourceIRI.ToString(); Boolean foundLabel = false; VirtuosoDataAdapter getLabelAdapter = new VirtuosoDataAdapter(); DataSet getLabelDataSet = new DataSet(); //Try finding it in resources graph first foreach (String graph in graphList) { StringBuilder getLabelCommandText = new StringBuilder("sparql select * from <" + graph + "> where {<" + SourceIRI.ToString() + "> ?p ?o}"); VirtuosoCommand getLabelCommand = new VirtuosoCommand(getLabelCommandText.ToString(), ParentConnection); getLabelAdapter.SelectCommand = getLabelCommand; try { getLabelAdapter.Fill(getLabelDataSet); foreach (DataRow getLabelRow in getLabelDataSet.Tables[0].Rows) { if (getLabelRow[0].ToString() == "http://www.w3.org/2000/01/rdf-schema#label") { labelText = getLabelRow[1].ToString(); foundLabel = true; break; } } } catch { } if (foundLabel) { GraphUsed = graph; break; } } // If we still have no label try the predicate itself as the graph if (!foundLabel) { GraphUsed = SourceIRI.ToString(); StringBuilder getLabelCommandText = new StringBuilder("sparql define get:soft \"soft\" select * from <" + GraphUsed + "> where {<" + SourceIRI.ToString() + "> ?p ?o}"); VirtuosoCommand getLabelCommand = new VirtuosoCommand(getLabelCommandText.ToString(), ParentConnection); getLabelAdapter.SelectCommand = getLabelCommand; try { getLabelAdapter.Fill(getLabelDataSet); foreach (DataRow getLabelRow in getLabelDataSet.Tables[0].Rows) { if (getLabelRow[0].ToString() == "http://www.w3.org/2000/01/rdf-schema#label") { labelText = getLabelRow[1].ToString(); break; } } } catch { } } return labelText; }
List<IRILabel> labelList = new List<IRILabel>();
Label propertyLabel = new Label();
IRILabel propertyLabel = new IRILabel(row[0], graphList, ParentConnection);
propertyLabel.Text = getLabelText(row[0]);
public void label_Click(object sender, EventArgs e) { int labelNum = 0; for (int i = 0; i < labelList.Count; i++) { if (sender == labelList[i]) { labelNum = i; break; } } SqlExtendedString se = labelList[labelNum].iri; ExtendedStringHandler seHandler = new ExtendedStringHandler(se, ParentConnection, labelList[labelNum].graph); seHandler.displayData(); }
public ExtendedStringHandler(SqlExtendedString iri, VirtuosoConnection parentConnetion, String graph) { ParentConnection = parentConnetion; if (iri.IriType == SqlExtendedStringType.IRI) { ParentIRI = iri; isIRI = true; DescribeCommandSimple = new StringBuilder("sparql select * from <http://localhost:8890/Northwind> where {<" + iri.ToString() + "> ?p ?o}"); DescribeCommandGeneral = new StringBuilder("sparql define get:soft " + '"'.ToString() + "soft" + '"'.ToString() + " select * from <" + graph + "> where { <" + iri.ToString() + "> ?p ?o }"); } }