I am working with Grakn and I want to undefine an attribute.
To do this, do I first have to undefine it from an entity?
For example, if I have the below:
person sub entity, has name;
name sub attribute, datatype string;
Can I do this:
undefine
name sub attribute;
In Graql, you can indeed undefine an attribute as you indicated:
undefine
name sub attribute;
don't forget to commit after!
https://dev.grakn.ai/docs/schema/concepts
Related
The grakn server version is 1.3.0.
I have a 4000+ line CSV file, each line stands for an employee profile record. The CSV file has a column called Reportingline, which stands for the EmployeeID of the employee's line manage.
I can successfully migrate my CSV data into my Grakn keyspace, but when I use the following query I can only get one record returned.
match
$e isa employee has report-line "00136450";get;
without 'contains' only 1 result returned
The results are correct when I change the above query as below, but significantly this is a big performance hit.
match
$e isa employee has report-line contains "00136450";get;
with 'contains' the result is correct
Can anyone point out what is wrong with my query? How do I get the full results without contains keyword?
I use the following schema to define an employee
employee sub entity
plays superior
plays subordinate
has employee-id
has employee-name
has report-line
has bu
has email
has phone-number
has division
has title;
employee-id sub attribute datatype string;
employee-name sub attribute datatype string;
report-line sub attribute datatype string;
bu sub attribute datatype string;
email sub attribute datatype string;
phone-number sub attribute datatype string;
division sub attribute datatype string;
title sub attribute datatype string;
I use the following template to migrate the CSV data.
$x isa employee,
has employee-id <EmployeeID>,
has employee-name <EmployeeName>,
has report-line <ReportLine>,
if(<BU>!=null) do { has bu <BU>,}
has email <Email>,
if(<PhoneNumber>!=null) do { has phone-number <PhoneNumber>,}
if(<Division>!=null) do { has division <Division>,}
has title <Title>;
Thank you for reporting this issue. I am writing here to confirm that the bug has been fixed in Grakn 1.4.0.
I tryout some ways to use postsharp
The definition of one of my custom aspects looks like:
<Serializable> _
<MulticastAttributeUsage(PersistMetaData:=True)> _
Public Class StringChecker
Inherits LocationInterceptionAspect
Public Overrides Sub OnGetValue(ByVal args As LocationInterceptionArgs)
MyBase.OnGetValue(args)
..... ..... .....
When I try to find all classes that are tagged with the attribute / aspect , the result ist always empty.
I use this code to discover the assemblys at runtime:
Dim targetClasses As IEnumerable(Of Type) = From asm In AppDomain.CurrentDomain.GetAssemblies().Where(Function(A) A.FullName.Contains("MyNameSpace")) _
.SelectMany(Function(A) A.GetTypes()) _
.Where(Function(T) T.IsDefined(GetType(StringChecker), True))
When I use for testing proposals, a normal atttribute, the query delivers the espected types.
Hoppefully some can give me a hint what I have to do.
edit: It looks like the custom attributes can only be found in the class propertys..
Regards,
Markus
There are two ways to do it:
Use ReflectionSearch but it does not retrieve aspects added with IAspectProvider.
Use IAspectRepositoryService
Can anyone help explain why the following will change a value in an object's member even if I pass it in ByVal?
Scenario: The name of the person is 'Sab' but when i pass the object in the sub routine, the name changes to 'John'.
I thought object types are passed in by reference only and should not be changed unless forced. Is this a feature in .NET and what is this behavior called?
Sub Main()
Dim p As New Person
p.name = "Sab"
DoSomething(p)
Console.WriteLine(p.name) ' John
Console.Read()
End Sub
Public Sub DoSomething(ByVal p As Person)
p.name = "John"
End Sub
Writing to p.name is not the same as writing to p. ByVal prevents the parameter itself from being modified, e.g.
p = New Person
If you want to prevent the properties of Person from being written to, then you need to re-design the Person class to be immutable instead of mutable. Whether this is an appropriate thing to do depends on how you want your code to behave.
Example:
Public Class Person
' All fields are private
Private _name As String
' All properties are read only
Public ReadOnly Property Name As String
Get
Return _name
End Get
End Property
' Field values can *only* be set in the constructor
Public Sub New(name As String)
_name = name
End Sub
End Class
An instance of an object is a reference - it's a pointer to the object. If you pass any object by value, you are passing it's reference by value. Effectively, there is no difference in passing an object by value or by reference. .Net creates a new copy of the reference and passes it's value to your method but the new copy of the reference still points to the same object. Some folks say that "all objects are passed by reference" but this is not true, the reference to the object in the called method is NOT the same as the reference in the caller but they point to the same object.
If you really want to pass a copy of the object such that the called method may not modify the originals' properties, then you need to create a copy. See discussions about shallow vs deep copies and be careful to understand references to objects vs simple data types. Do think about your design though. It's rare to actually need to create a copy rather than a new object.
I guess I'm missing something here, but I can't find a way to pass a simple variable from my code behind file to the .aspx page.
In code behind I have:
Dim test As String = "test"
and in my aspx page I try: <%=test %>
that gives me the following error:
Error 2 'test' is not declared. It may be inaccessible due to its protection level
Am I forgetting something here?
Declare test as a property (at the class level) instead of a local variable, then refer to it as you currently do in your markup (aspx).
VB.NET 10 (automatic properties):
Protected Property test As String = "Test"
Pre-VB.NET 10 (no support for automatic properties)
Private _test As String
Protected Property Test As String
Get
Return _test
End Get
Set(value As String)
_test = value
End Set
End Property
With the property in place you should assign a value to it directly in your code-behind.
Use the protected modifier.
Protected test As String = "test"
Change the code to
Protected test As String = "test" (in .vb file)
<%=Me.test%> (inside the markup)
EDIT: As suggested by #Ahmed, it is better to create a property instead of a variable such as the one I have provided.
Try changing it to...
Public test As String = "test"
then it should work.
From here http://msdn.microsoft.com/en-us/library/76453kax.aspx ...
At the module level, the Dim statement without any access level keywords is equivalent to a
Private declaration. However, you might want to use the Private keyword to make your code
easier to read and interpret.
Declare variable either protected or public:
Protected test As string = "test"
And in .aspx file:
<%=test%>
I would like to extend the System.Web.HttpContext.User object (ASP.NET/VB.NET) so that it contains other fields besides just Name. I understand I can create an object that inherits the System.Security.Principal.GenericPrincipal class, but how do I store that in the Current.User object in a usable fashion. ie, I can do something like Current.User.UserID.
So far to achieve this I've created a kludgy workaround by using | delimited strings in the User.Name property and then splitting them, but it's getting kind of ridiculous.
Any suggestions?
Thanks!
EDIT: I have tried the following to no avail:
Imports System.Security.Principal
Public Class CurrentUser : Inherits GenericPrincipal
Private _totalpoints As Integer
Private _sentencecount As Integer
Private _probationuntil As DateTime
Public ReadOnly Property TotalPoints() As Integer
Get
Return _totalpoints
End Get
End Property
Public ReadOnly Property SentenceCount() As Integer
Get
Return _sentencecount
End Get
End Property
Public ReadOnly Property ProbationUntil() As DateTime
Get
Return _probationuntil
End Get
End Property
Public Sub New(ByVal principle As IIdentity, ByVal roles() As String, _
ByVal points As Integer, ByVal sentences As Integer, ByVal probationTil As DateTime)
MyBase.New(principle, roles)
_totalpoints = points
_sentencecount = sentences
_probationuntil = FixDBNull(probationTil)
End Sub
End Class
setting the object in my Global.asax Application_AuthenticateRequest function like so:
HttpContext.Current.User = New CurrentUser(User, userRoles, _
points, sentenceCount, probationUntil)
with a direct cast wherever the object is needed like so:
Dim thisUser As CurrentUser = DirectCast(Current.User, CurrentUser)
i also tried CType and it didn't work... my error is
[InvalidCastException: Unable to cast object of type 'System.Security.Principal.GenericPrincipal' to type 'myProject.CurrentUser'.]
i'm losing my mind here ... :( thanks guys...
anyone?
You can create your own Principal class with the required properties, that inherits from a Generic Principal, and then set the User property of your Current Context to be the a user of that type.
The example below is for ASP.Net MVC but a similar approach could be used with webforms.
You can do this in the PostAuthenticateRequest after a user is authenticated (in the Global.asax)
private void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
{
SomePrincipal newUser = new SomePrincipal(User.Identity, tmpRoles);
senderRef.Context.User = newUser;
System.Threading.Thread.CurrentPrincipal = newUser;
}
You could then add a property or method in a base class of your page (or controller) for example that to wrap and type the Context.User principal to your Principal type and make sure you call it rather than calling the one on the HttpContext.
There are probably other solutions too!
Would this approach work for you? It looks a little involved but it really doesn't take too long to setup:
Create a 'base' class of your own, and have your pages inherit from that. For example, create a base class called 'BasePage' which inherits from System.Web.UI.Page.
Have your ASP.net pages inherit from your new BasePage class.
In the BasePage class, you can have a public property which contains the extra fields you want to store for your user (eg. BasePage.FirstName, BasePage.LastName). Better still, create a User object containing the extra fields, and expose that via BasePage, eg. "BasePage.Customer". This keeps things tidy if you plan to extend BasePage later.
You can then override the OnInit() of the base class to check for HTTPContext.Current.User.Name property, and fetch the necessary info from your DB to initialise your custom properties.
You can modify the code so that it won't need to hit the database each time the page is refreshed by using ControlState to check whether the custom fields have values before populating them again from the database.
Hope this helps...
Richard.