delete a node or triple using dotenetrdf librery? - c#

I have an n3 file formate and i want to delete a node or triple from it how can i do it? should i use sparql query?please help me
i want to have an n3 file and want to delete a node from it.
i pass a graph that use in my parent form to this delete form and want to work with this graph that i create from an n3 file i mean i read this n3 file and convert it to a graph and send it to this form.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VDS.RDF;
using VDS.RDF.Parsing;
using VDS.RDF.Query;
using System.IO;
using System.Windows;
using System.Runtime.InteropServices;
using VDS.RDF.Writing;
namespace WindowsFormsApplication2
{
public partial class delete : Form
{
Graph gra = new Graph();
public delete(Graph initialValue)
{
InitializeComponent();
ValueFromParent = initialValue;
}
private void delete_Load(object sender, EventArgs e)
{
}
public Graph ValueFromParent
{
set
{
this.gra = value;
}
}
}
}

From the documentation on Working with Graphs please see the section titled Asserting and Retracting triples which makes mention of the Assert() and Retract() methods which can be used to do what you've asked.
For example to delete a specific Triple:
//Assuming you already have the triple to delete in a variable t
g.Retract(t);
Or perhaps more usefully deleting all Triples that match a specific Node:
g.Retract(g.GetTriplesWithSubject(g.CreateUriNode(new Uri("http://example.org"))));
If you aren't sure whether a specific Node exists you can do something like the following:
INode n = g.GetUriNode(new Uri("http://example.org"));
//If n is null then the specified Node does not exist in the Graph
if (n != null)
{
g.Retract(g.GetTriplesWithSubject(n));
}
Note that you can't directly delete a Node from the Graph other than by removing all Triples that have it in the Subject/Object position. Also note that this does not remove it from the collection provided by the Nodes property of the Graph currently.
Yes you can also do this via SPARQL but for just removing a few triples that is very much overkill unless you need to remove triples based on some complex criteria which is not easily expressed directly using API selection and retraction methods.

Related

Select IFC Physical Simple Quantity of Wall

I'm using XBim IFC libraries in order to get some info of a Building model elements.
Specifically, of IfcWall entities.
I have to acces Wall Base Quantities (lenght, height, width, etc.) but I cant reach those properties from IfcWall class.
I have this class:
using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xbim.Ifc;
using Xbim.Ifc4.ActorResource;
using Xbim.Ifc4.DateTimeResource;
using Xbim.Ifc4.ExternalReferenceResource;
using Xbim.Ifc4.PresentationOrganizationResource;
using Xbim.Ifc4.GeometricConstraintResource;
using Xbim.Ifc4.GeometricModelResource;
using Xbim.Ifc4.GeometryResource;
using Xbim.Ifc4.Interfaces;
using Xbim.Ifc4.Kernel;
using Xbim.Ifc4.MaterialResource;
using Xbim.Ifc4.MeasureResource;
using Xbim.Ifc4.ProductExtension;
using Xbim.Ifc4.ProfileResource;
using Xbim.Ifc4.PropertyResource;
using Xbim.Ifc4.QuantityResource;
using Xbim.Ifc4.RepresentationResource;
using Xbim.Ifc4.SharedBldgElements;
namespace ProcesadorPremoldeado.IFC
{
public class IFCCalculos
{
public void CalculoPlacas(string fileName, XbimEditorCredentials editor)
{
using (var model = IfcStore.Open(fileName, editor))
{
using (var transaction = model.BeginTransaction("Quick start transaction"))
{
//get all Walls in the model
var ifcWallsList = model.Instances.OfType<IfcWall>();
foreach (var wall in ifcWallsList)
{
var prop = wall.PhysicalSimpleQuantities.Where(x=>x.Name=="Height");
}
transaction.Commit();
}
}
}
}
}
That lambda expression return me a row, correctly filtered by Name parameter, as this property is accessible.
But I cant access the property call "LengthValue", the strange thing is that the property is visible during debbugin if I put a breakpoint, under "prop" list in the foreach loop.
Anyone could give me an idea of what could be happening?
Thanks in advance!
This is because LengthValue is a property of IfcQuantityLength, but PhysicalSimpleQuantities are of supertype IfcPhysicalQuantity. You just need to select quantities of the right type
var height = wall.PhysicalSimpleQuantities
.OfType<IfcQuantityLength>()
.Where(x=>x.Name=="Height")?
.LengthValue;

Linq and localhost, entity namespace is different than program namespace but still get error

I have tried to search for this but every example I find has a problem like them actually having the same namespace as their class or something.
I am simply trying to start using Linq. When I add new item Host is localhost. I have my database in Visualstudio and my project name is different than the DataContext name but I can't get it initialized. I get error:
'LinkedContext' is a namespace but is used like a type'
here is code...
namespace TryAgain
{
class Program
{
static void Main(string[] args)
{
LinkedContext db = new LinkedContext();
}
}
}
LinkedContext doesn't work? In settings of the Database Diagram it says the Entity Namespace is 'LinkedContext' So what am I missing. I thought I saw you could run that one line of code to connect your database that is already in VisualStudio due to adding a new item and then start playing with it? I just want to be able to practice with a database! Do stuff like:
var example = from x in example.Table
orderby x.field
select x;
you need using LinkedContext at the top of your file. the error you’re getting is telling you LinkedContext is a namespace but you’re treating like a type, ie a class. once you define it at the top you can then use the type that you need within that namespace.
added "using LinkedContext" to the top of code then also had to use LinkedDataContext not just LinkedContext:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LinkedContext;
namespace TryAgain
{
class Program
{
static void Main(string[] args)
{
LinkedDataContext db = new LinkedDataContext();
var example = from x in db.employees
orderby x.employee_id
select x;
foreach (var whatever in example)
{
Console.WriteLine(whatever.name);
}

List comparison not working

I'm trying to make an application that reads two text files, takes the two, and merges them into one single list. Then take said list, and compare it to another list (from another text file). The problem is that no matter what I do my program always goes to else (see the line where it says
if (BoysAndGirlsList.Contains(NameEntered) && MostPopularNamesList.Contains(NameEntered))
). I don't know why it does this.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Linq; //Needed for concat.
namespace Name_Search
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string BoyNames = System.IO.File.ReadAllText(#"D:\Google Drive\Course Work\C# Intro\Student Sample Programs\Chap07\BoyNames.txt"); //Reads BoyNames txt file.
List<string> BoyNamesList = BoyNames.Split('\n').ToList(); //Converts it to a list.
//BoyNamesList.ForEach(Console.WriteLine); <-Testing to make sure that the list is working properly.
string GirlNames = System.IO.File.ReadAllText(#"D:\Google Drive\Course Work\C# Intro\Student Sample Programs\Chap07\GirlNames.txt"); //Reads GirlNames txt file.
List<string> GirlNamesList = GirlNames.Split('\n').ToList(); //Converts it to a list.
List<string> BoysAndGirlsList;
BoysAndGirlsList = BoyNamesList.Concat(GirlNamesList).ToList(); //Adds the lists together.
//BoysAndGirlsList.ForEach(Console.WriteLine); <-Again just testing that the list is working.
string MostPopularNames = System.IO.File.ReadAllText(#"D:\Google Drive\Course Work\C# Intro\Student Sample Programs\Chap07\MostPopularBoyAndGirlNames.txt"); //Reads MostPopularBoyAndGirlNames txt file. Compiled from http://goo.gl/1crLcY.)
List<string> MostPopularNamesList = MostPopularNames.Split('\n').ToList(); //Converts it to a list.
string NameEntered = nameInput.Text;
if (BoysAndGirlsList.Contains(NameEntered) && MostPopularNamesList.Contains(NameEntered))
{
MessageBox.Show("This name is one the most popular names!");
}
else
{
MessageBox.Show("This is not one of the most popular names.");
}
}
}
}
What is not working properly here? I've tried putting in a break, and when I did the values looked fine to me.
The issue is probably solved as mentioned by the comments, where redundant spaces in the 'names' causes them to compare unequally. You also have an issue when you want to compare names in a case-insensitive manner.
The first issue can be solved by trimming whitespace from each name:
BoysAndGirlsList = BoysAndGirlsList.Select(name => name.Trim()).ToList();
MostPopularNamesList = MostPopularNamesList.Select(name => name.Trim()).ToList();
The second issue can be solved by using an invariant case comparer:
if (BoysAndGirlsList.Contains(NameEntered, StringComparer.InvariantCultureIgnoreCase) &&
MostPopularNamesList.Contains(NameEntered, StringComparer.InvariantCultureIgnoreCase))

unable to connect to R from c#

I am trying to connect to R from c# using the following code. It looks like C# is not reading the R dll files. My R installation directory is this:
C:\Users\R-2-13\R-2.13.0\bin\i386
and I also downloaded and put the R.NET.dll in the same directory. In Visual Studio, I set the reference to R.NET.dll file. When I run the following code, the code goes the the catch section "unable to find the R Installation". Any ideas? Has anybody got this working?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RDotNet;
namespace RNet_Calculator
{
public partial class Form1 : Form
{
// set up basics and create RDotNet instance
// if anticipated install of R is not found, ask the user to find it.
public Form1()
{
InitializeComponent();
bool r_located = false;
while (r_located == false)
{
try
{
REngine.SetDllDirectory(#"C:\Users\R-2-13\R-2.13.0\bin\i386");
REngine.CreateInstance("RDotNet");
r_located = true;
}
catch { MessageBox.Show(#"Unable to find R installation's \bin\i386 folder. Press OK to attempt to locate it.");
MessageBox.Show("error");
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
This is http://rdotnet.codeplex.com/ (RDotNet) to develop Winform applications. While I know Shiny and all the other Web-like R-tools quite well, the combination of c# and R still is my preferred end-user combinations. Try simple things like disabling buttons with Shiny...
Too bad rdotnet is quite buggy; in the current version, it crashes on R exeptions, even in try-catched ones.
This said: please make absolutely sure that you use version 1.5, not the stupidly called "stable" (=early beta) version on the page. Best download it via NuGet. Also check if you did not mix 32bit R with 64 bit c#.
Using the Helper-functions of 1.5, initialization is:
Helper.SetEnvironmentVariables();
engine = REngine.CreateInstance(EngineName);
engine.Initialize();
# Assuming you want to catch the graphic window, use my RGraphAppHook
# on the rdotnet site http://rdotnet.codeplex.com/workitem/7
cbt = new RGraphAppHook { GraphControl = GraphPanelControl };

Im getting exception Typeload what the exception can be?

I added as reference 3 dll's: Google.Apis , Google.Apis.Translate.v2 , System.Runtime.Serialization
In Form1 i have one line:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Translator.translate(new TranslateInput());
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Now the error the exception is on the first line in the class Translator:
The line that throw the error is: var service = new TranslateService { Key = GetApiKey() };
The class code is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Web;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using Google.Apis.Util;
using Google.Apis.Translate.v2;
using Google.Apis.Translate.v2.Data;
using TranslationsResource = Google.Apis.Translate.v2.Data.TranslationsResource;
public class Translator
{
public static string translate(TranslateInput input)
{
// Create the service.
var service = new TranslateService { Key = GetApiKey() };
string translationResult = "";
// Execute the first translation request.
Console.WriteLine("Translating to '" + input.TargetLanguage + "' ...");
TranslationsListResponse response = service.Translations.List(input.SourceText, input.TargetLanguage).Fetch();
var translations = new List<string>();
foreach (TranslationsResource translation in response.Translations)
{
translationResult = translation.TranslatedText;
}
return translationResult;
}
private static string GetApiKey()
{
return "AIzaSyCjxMe6RKHZzd7xSfSh2pEsBqUdXYm5tA8"; // Enter Your Key
}
}
/// <summary>
/// User input for this example.
/// </summary>
[Description("input")]
public class TranslateInput
{
[Description("text to translate")]
public string SourceText = "Who ate my candy?";
[Description("target language")]
public string TargetLanguage = "fr";
}
The error is:
Could not load type 'Google.Apis.Discovery.FactoryParameterV1_0' from assembly 'Google.Apis, Version=1.1.4497.35846, Culture=neutral, PublicKeyToken=null'.
Tried to google for help and also tried to change the project type to x64 platform but it didnt help. So i put it back on x86
I have windows 7 64bit visual studio c# 2010 pro .net 4.0 profile client.
Cant figure out what is the error ?
This error as reported in the above-posted messages is due to a local copy in the bin\Debug folder of your solution or project. Even though you attempt to clean your solution, such copies will persist to exist.
In order to avoid this to happen, you have to force Visual Studio to refer to the correct DLL by adding reference paths within a project properties. Unfortunately, if you got several projects within your solutions, you will have to set the reference paths for the projects one after another until completed.
Should you wish to know how to setup reference paths follow these simple instructions:
1.Select your project, right-click, then click "Properties";
2.In the project properties, click "Reference Paths";
3.Folder, type or browse to the right location of your DLL, click [Add Folder].
You will need to perform these steps for as many different locations you may have for each of your DLLs. Consider setting an output path under the Build tab of the same project properties, so that you may output your DLLs in the same directory for each of them, thus assuring you to find all the latest builds under the same location, simplifying forward your referencing.
Note this can only be one reason for this error. But it is sure that is has to do something with a wrong copy of the mentioned assembly.

Categories

Resources