public bool HasResourceDenotedBy(GraphMember theMember) { MySqlCommand cmd = new MySqlCommand("SELECT EXISTS (SELECT * FROM ResourceNodes WHERE graphId = " + itsHashCode + " AND nodeHash = " + theMember.GetHashCode() + ")", itsConn); return(Convert.ToInt32(cmd.ExecuteScalar()) > 0); }
public void AddDenotation(GraphMember member, Resource theResource) { MySqlCommand cmd = new MySqlCommand("INSERT IGNORE INTO ResourceNodes (graphId, resourceHash, nodeHash) VALUES (" + itsHashCode + ", " + theResource.GetHashCode() + ", " + member.GetHashCode() + ")", itsConn); cmd.ExecuteNonQuery(); }
public virtual Resource GetResourceDenotedBy(GraphMember theMember) { ArrayList list = new ArrayList(); list.Add(theMember); IDictionary resourcesIndexedByNode = itsWriteStrategy.CreateAndGetResourcesDenotedBy(list); return((Resource)resourcesIndexedByNode[theMember]); }
public bool Contains(GraphMember thePredicate, GraphMember theObject) { if (!itsStore.HasResourceDenotedBy(theObject)) { return(false); } Resource theObjectResource = itsStore.GetResourceDenotedBy(theObject); return(Contains(thePredicate, theObjectResource)); }
public Resource MakeNewResourceForNode(GraphMember theMember) { if (theMember.IsSelfDenoting()) { return(new Resource(theMember)); } else { return(new Resource()); } }
public bool Contains(GraphMember thePredicate, Resource theObjectResource) { if (!itsStore.HasResourceDenotedBy(thePredicate)) { return(false); } Resource thePredicateResource = itsStore.GetResourceDenotedBy(thePredicate); ResourceStatement testStatement = new ResourceStatement(itsResource, thePredicateResource, theObjectResource); return(itsStore.Contains(testStatement)); }
/// <returns>A resource denoted by the subject if the subject is known, otherwise a new resource</returns> public virtual Resource GetResourceDenotedBy(GraphMember theMember) { if (itsNamedResources.ContainsKey(theMember)) { return((Resource)itsNamedResources[theMember]); } else { Resource resource = MakeNewResourceForNode(theMember); AddDenotation(theMember, resource); return(resource); } }
public void AddDenotation(GraphMember member, Resource theResource) { itsNamedResources[member] = theResource; if (HasNodeDenoting(theResource)) { ((ArrayList)itsResourceDenotations[theResource]).Add(member); } else { ArrayList nodeList = new ArrayList(); nodeList.Add(member); itsResourceDenotations[theResource] = nodeList; } }
public void Add(GraphMember thePredicate, GraphMember theObject) { Resource theObjectResource; if (itsStore.HasResourceDenotedBy(theObject)) { theObjectResource = itsStore.GetResourceDenotedBy(theObject); } else { theObjectResource = itsStore.MakeNewResourceForNode(theObject); itsStore.AddDenotation(theObject, theObjectResource); } Add(thePredicate, theObjectResource); }
public void Add(GraphMember thePredicate, Resource theObjectResource) { Resource thePredicateResource; if (itsStore.HasResourceDenotedBy(thePredicate)) { thePredicateResource = itsStore.GetResourceDenotedBy(thePredicate); } else { thePredicateResource = itsStore.MakeNewResourceForNode(thePredicate); itsStore.AddDenotation(thePredicate, thePredicateResource); } ResourceStatement resourceStatement = new ResourceStatement(itsResource, thePredicateResource, theObjectResource); itsStore.Add(resourceStatement); }
private IList GetNodesDenoting(Resource theResource, bool onlyTheBest) { ArrayList theNodes = new ArrayList(); MySqlCommand cmd = new MySqlCommand( "SELECT rn.nodeHash, rn.nodeType, u.uri, pl.value, l.value, tl.value, t.value " + "FROM resourcenodes rn " + "LEFT OUTER JOIN UriRefs u ON rn.nodeHash=u.hash AND rn.nodeType='u' " + "LEFT OUTER JOIN Plainliterals pl ON rn.nodeHash = pl.hash AND rn.nodeType='p' " + "LEFT OUTER JOIN Languages l ON pl.languageHash = l.hash " + "LEFT OUTER JOIN TypedLiterals tl ON rn.nodehash = tl.hash AND rn.nodeType = 't' " + "LEFT OUTER JOIN DataTypes t ON tl.datatypeHash = t.hash " + "WHERE rn.graphId = " + itsHashCode + " AND rn.resourceHash = " + theResource.GetHashCode() + (onlyTheBest == true ? " LIMIT 1" : ""), itsConn); MySqlDataReader dataReader = cmd.ExecuteReader(); int nodeHash; char nodeType; while (dataReader.Read()) { nodeHash = dataReader.GetInt32(0); nodeType = dataReader.GetChar(1); GraphMember node = null; switch (nodeType) { case 'u': node = new UriRef(dataReader.GetString(2)); break; case 'b': node = new BlankNode(nodeHash); break; case 'p': node = new PlainLiteral(dataReader.GetString(3), dataReader.GetString(4)); break; case 't': node = new TypedLiteral(dataReader.GetString(5), dataReader.GetString(6)); break; } theNodes.Add(node); } dataReader.Close(); return(theNodes); }
public bool Contains(GraphMember thePredicate, GraphMember theObject) { return(false); }
public virtual void BindNode(Atom key, GraphMember value) { itsNodesIndexedByAtom[key] = value; }
public void SetNode(string variableName, GraphMember member) { itsResourceNodes[itsBindings[variableName]] = member; }
public void AddDenotation(GraphMember member, Resource theResource) { itsStore.AddDenotation(member, theResource); }
public XmlDocument Build(IEnumerator solutions, SparqlQuery query) { XmlDocument doc = new XmlDocument(); XmlElement rootElement = doc.CreateElement("", "sparql", "http://www.w3.org/2005/sparql-results#"); doc.AppendChild(rootElement); XmlElement headElement = doc.CreateElement("", "head", "http://www.w3.org/2005/sparql-results#"); rootElement.AppendChild(headElement); foreach (Variable variable in query.Variables) { XmlElement variableElement = doc.CreateElement("", "variable", "http://www.w3.org/2005/sparql-results#"); XmlAttribute variableNameAttribute = doc.CreateAttribute("", "name", ""); variableNameAttribute.Value = variable.Name; variableElement.SetAttributeNode(variableNameAttribute); headElement.AppendChild(variableElement); } XmlElement resultsElement = doc.CreateElement("", "results", "http://www.w3.org/2005/sparql-results#"); XmlAttribute orderedAttribute = doc.CreateAttribute("", "ordered", ""); if (query.IsOrdered) { orderedAttribute.Value = "true"; } else { orderedAttribute.Value = "false"; } resultsElement.SetAttributeNode(orderedAttribute); XmlAttribute distinctAttribute = doc.CreateAttribute("", "distinct", ""); if (query.IsDistinct) { distinctAttribute.Value = "true"; } else { distinctAttribute.Value = "false"; } resultsElement.SetAttributeNode(distinctAttribute); rootElement.AppendChild(resultsElement); while (solutions.MoveNext()) { QuerySolution solution = (QuerySolution)solutions.Current; XmlElement resultElement = doc.CreateElement("", "result", "http://www.w3.org/2005/sparql-results#"); resultsElement.AppendChild(resultElement); foreach (Variable variable in query.Variables) { XmlElement bindingElement = doc.CreateElement("", "binding", "http://www.w3.org/2005/sparql-results#"); XmlAttribute bindingNameAttribute = doc.CreateAttribute("", "name", ""); bindingNameAttribute.Value = variable.Name; bindingElement.SetAttributeNode(bindingNameAttribute); resultElement.AppendChild(bindingElement); XmlElement elementNodeType; if (solution.IsBound(variable.Name)) { GraphMember member = solution.GetNode(variable.Name); if (member is UriRef) { elementNodeType = doc.CreateElement("", "uri", "http://www.w3.org/2005/sparql-results#"); } else if (member is BlankNode) { elementNodeType = doc.CreateElement("", "bnode", "http://www.w3.org/2005/sparql-results#"); } else if (member is PlainLiteral) { elementNodeType = doc.CreateElement("", "literal", "http://www.w3.org/2005/sparql-results#"); if (null != ((PlainLiteral)member).GetLanguage()) { XmlAttribute languageAttribute = doc.CreateAttribute("xml", "lang", "http://www.w3.org/XML/1998/namespace"); languageAttribute.Value = ((PlainLiteral)member).GetLanguage(); elementNodeType.SetAttributeNode(languageAttribute); } } else if (member is TypedLiteral) { elementNodeType = doc.CreateElement("", "literal", "http://www.w3.org/2005/sparql-results#"); XmlAttribute datatypeAttribute = doc.CreateAttribute("", "datatype", ""); datatypeAttribute.Value = ((TypedLiteral)member).GetDataType(); elementNodeType.SetAttributeNode(datatypeAttribute); } else { throw new ApplicationException("Unsupported graph member type"); } XmlText valueText = doc.CreateTextNode(solution.GetNode(variable.Name).GetLabel()); elementNodeType.AppendChild(valueText); } else { elementNodeType = doc.CreateElement("", "unbound", "http://www.w3.org/2005/sparql-results#"); } bindingElement.AppendChild(elementNodeType); } } return(doc); }
public Resource GetResourceDenotedBy(GraphMember theMember) { return(new Resource()); }
public bool HasResourceDenotedBy(GraphMember theMember) { return(itsNamedResources.ContainsKey(theMember)); }
public void AddDenotation(GraphMember member, Resource theResource) { // NOOP }
public bool HasResourceDenotedBy(GraphMember theMember) { return(false); }
public bool HasDenotation(GraphMember theMember, Resource theResource) { return(itsNamedResources[theMember].Equals(theResource)); }
public bool Contains(GraphMember thePredicate, Resource theObjectResource) { return(false); }
public GraphMemberExpression(GraphMember member) { itsMember = member; }
public void ExecuteQuery() { ArrayList solutions = new ArrayList(); if (SolutionIsPossible) { MySqlDataReader dataReader = null; try { dataReader = itsTriples.ExecuteSqlQuery(itsQuerySql); while (dataReader.Read()) { QuerySolution solution = new QuerySolution(); int col = 0; foreach (Variable var in itsSelectedVariables) { object resourceHash = dataReader.GetValue(col); if (!resourceHash.Equals(DBNull.Value)) { Resource resource = new Resource(Convert.ToInt32(resourceHash)); solution[var.Name] = resource; int nodeHash = dataReader.GetInt32(col + 1); char nodeType = dataReader.GetChar(col + 2); string lexicalValue = dataReader.GetString(col + 3); object rawSubValue = dataReader.GetValue(col + 4); string subValue = null; if (!rawSubValue.Equals(DBNull.Value)) { subValue = (string)rawSubValue; } GraphMember node = null; switch (nodeType) { case 'u': node = new UriRef(lexicalValue); break; case 'b': node = new BlankNode(nodeHash); break; case 'p': node = new PlainLiteral(lexicalValue, subValue); break; case 't': node = new TypedLiteral(lexicalValue, subValue); break; } solution.SetNode(var.Name, node); } col += 5; } solutions.Add(solution); } } catch (MySqlException e) { throw new ApplicationException("Error executing '" + itsQuerySql + "' for query " + itsQuery, e); } finally { if (null != dataReader) { dataReader.Close(); } } } itsSolutions = solutions.GetEnumerator(); }