### Changing the name of a navigation property in the Entity Framework

When you let the Entity Framework Designer in VS2008 generate the model from your database, the navigation properties of your objects will be based on the table names. Thus, assuming the presence of tables Customers and Orders and the presence of a foreign key from Orders to Customers, the designer will generate a business object class Orders with a collection property named Customers (cf. the ubiquitous Northwind database). This is less than ideal for two reasons:

• I don’t like the plural form of the property Customers on an order since it identifies a single customer, namely the customer having placed the order
• What happens if you decide to add yet another foreign key referencing the Customers table from Orders (maybe the customer was prompted to place the order by someone else – it’s a bit contrived but you get the idea)? What should we call the property on an order representing this relationship?

In the second case, the name of the referenced type/table is no good, since that is already in use. As it turns out, the EF Designer tries to name the property after the referenced type but adds a digit to avoid the name clash. Thus, the new property will be named “Customers1″. This conveys absolutely no information about the meaning of this property, so it is pretty useless.

The easy way to fix the problems mentioned above is to find the misbehaving properties in the designer, select them, press F2 (for ‘rename’) and rename them. This, however, is not a manageable solution if you are regenerating the EDMX regularly. In this case you will want to automate the process of opening up the EDMX in the XML Editor, finding the correct NavigationProperty in the CSDL region and performing a rename directly in the XML. In the example above the change might look like this:

<NavigationProperty Name=”Customers” Relationship=”NorthwindModel.FK_Orders_Customers” FromRole=”Orders” ToRole=”Customers” />

is changed to

<NavigationProperty Name=”Customer” Relationship=”NorthwindModel.FK_Orders_Customers” FromRole=”Orders” ToRole=”Customers” />

This may be automated using XSLT and nant.

### Building the Mulgara Semantic Store

Mulgara is an RDF datastore, that is, it is a database specifically designed for storing RDF data (triples). RDF is a W3C recommendation for describing facts about all sorts of resources. A very readable introduction to RDF is the W3C Recommendation RDF Primer.
I happened upon the Mulgara project last week, when I was surfing for articles on modal and description logics and the semantic web. I found the blog of Paul Gearon to be very interesting. Paul is the lead developer of Mulgara and as such blogs a lot about Mulgara. After listening to a few podcasts on the Nodalities blog I decided to have a go at building and toying with Mulgara. This is an account of my experiences building the Mulgara project.

### Preparations

#### Installing Eclipse

Go to www.eclipse.org to download the “Eclipse IDE for Java Developers” bundle.
I downloaded a ZIP file for Windows and extracted the contents to my Program Files folder and hit eclipse.exe.
The first time Eclipse starts it asks you where you want to place your workspace. The workspace is a location on disk much like the default Projects folder of Visual Studio. I accepted the default location, marked “Use this as default location and do not ask me again” and hit OK.

#### Installing the correct version of Java

My machine was equipped with Java SE 1.6, but Mulgara only supports 1.5, so I had to go to Sun’s website to get the Java SE Development Kit 5.0.
I now had both Java 1.5 and 1.6 installed. To have 1.5 chosen by default, I added the environment variable JAVA_HOME and had it point at C:\Program Files\Java\jdk1.5.0_15. I also set up the environment varialble MULGARA_HOME and pointed it to the place where I had placed the Mulgara source code, in this case C:\semantic web\Mulgara Source\mulgara-2.0-alpha. After having verified that these environment variables had taken effect, it was time to build the source.

### Building the project

In my command prompt I went on to the %MULGARA_HOME% directory and executed the command

build -projecthelp

Wohooo! The first sort of ‘interaction’ with the project Out comes a long list of build targets. Next, I executed

build.bat clean dist,

the compiler did its thing and presto! After 5 minutes and 25 seconds I was informed that “BUILD SUCCESSFUL”.
To have the Eclipse IDE perform dynamic compilation, you have to generate a number of files. Thus, next I executed

build ideSupport

When the build process completed, I generated the javadoc (build javadoc). This was a lengthy process, so I took the opportunity to piss about on Facebook. Up until now, it had been a smooth ride. However, after a while, the javadoc process aborted abruptly:
 [javadoc] C:\semantic web\Mulgara Source\mulgara-2.0-alpha\src\jar\sparql-interpreter\java\org\mulgara\sparql\SparqlIn rpreter.java:69: warning - @param argument "graph" is not a parameter name. [javadoc] java.lang.OutOfMemoryError: Java heap space 
I don’t expect to find the time to dive into the source code any time soon, so I decided to ignore this for now.

#### Building the server and the shell

Before building the server and shell artifacts it is recommended that you configure the logging framework, that is, the log4j appender. However, the clock had passed midnight, so I decided to go with the default settings for now.
Actually building the server and shell, thereby creating the files mulgara-2.0-alpha.jar and itql-2.0-alpha.jar files in the %MULGARAHOME%\dist directory, was just a matter of executing

 build dist 

Yet again, the compiler didn’t bat an eyelash and everything worked out nicely, BUILD SUCCESSFUL. Wow! At this point I was genuinely impressed. I’ve got to admit that, since it’s been years since I’ve done any Java development, I had anticipated having to fiddle with the environment, dependencies and the like for at least a couple of hours. Kudos to the Mulgara team  OK, so I had been waiting for this all weekend and I was pretty excited, so after a bit of air-drumming (I was listening to this excellent record at the time), crotch-grabbing and flexing of the biceps, I fired up the iTQL shell:

 java -jar %MULGARA_HOME%\dist\itql-2.0-alpha.jar and I was greeted by the shell:

Whew!

I still don’t know much about Mulgara, but I’ll continue to play around with it and post my findings in later installments of what I expect to be a series of posts on Mulgara.

Time for bed…

### Math in WordPress

1 Comment »

Last night I decided to investigate whether I would be able to publish math in my WordPress blog. I wanted to be able to write mathematical formulas and diagrams in some sort of markup language and have it rendered as it would be in a book – i.e. arrows should be real arrows, not just –>, parentheses should be properly sized etc.. At the moment, the most promising solution seems to be the LaTeX for WordPress plug-in. Using this plug-in you can embed LaTeX code directly in your blog by enclosing it in a pair of double-dollar-tags. When the page is displayed, the plug-in will append the LaTeX code to a URI and request a public Mimetex service at http://l.wordpress.com/latex.php, which will in turn respond with an image stream of the rendered formula. So, if I write

0 \to \text{Ker}(h) \stackrel{i}{\hookrightarrow} H^n(C;G) \stackrel{h}{\to} \text{Hom}(H_n(C),G) \to 0

I will get this:

$${0 \to \text{Ker}(h) \stackrel{i}{\hookrightarrow} H^n(C;G) \stackrel{h}{\to} \text{Hom}(H_n(C),G) \to 0}$$

Pretty sweet!
My only complaint would be that the public WordPress latex service doesn’t seem to support the rendering of commutative diagrams through the xy package: if I write

\xymatrix{ 0 \ar[r] & Z_{n+1} \ar[r]^i \ar[d]^0 & C_{n+1} \ar[r]^\partial \ar[d]^\partial & B_n \ar[r] \ar[d]^0 & 0 \\ 0 \ar[r] & Z_{n} \ar[r]^i & C_n \ar[r]^\partial & B_{n-1} \ar[r] & 0}

I get

$$\xymatrix{ 0 \ar[r] & Z_{n+1} \ar[r]^i \ar[d]^0 & C_{n+1} \ar[r]^\partial \ar[d]^\partial & B_n \ar[r] \ar[d]^0 & 0 \\ 0 \ar[r] & Z_{n} \ar[r]^i & C_n \ar[r]^\partial & B_{n-1} \ar[r] & 0}$$

while I would have expected something like

(I ran this through latex on my laptop, so I think it ought to parse).

All in all, I think the end result of the Latex for WordPress plug-in is pretty cool. In general, the lack of support for commutative diagrams in the public WordPress service is a minor issue, but since I expect to be blogging a bit about algebraic topology and category theory, I may put an effort into setting up a properly configured service, If I can find the time and a suitable environment.

It is worth noting that the browser always requests images from your webserver and never sends a request directly to the Mimetex service. Thus, the first time a formula is to be rendered, the webserver requests the image from the Mimetex service, caches the result locally and only then serves up the image to the browser. Obviously, this takes quite a burden off of the shoulders of the public Mimetex service providers.