<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Neural Network Design blog &#187; .net</title>
	<atom:link href="http://janbogaerts.name/index.php/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://janbogaerts.name</link>
	<description>My take on neural networks, AI and more</description>
	<lastBuildDate>Thu, 15 Dec 2011 18:43:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Scraping the Internet</title>
		<link>http://janbogaerts.name/index.php/2011/11/13/scraping-the-internet/</link>
		<comments>http://janbogaerts.name/index.php/2011/11/13/scraping-the-internet/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 12:48:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[chatbot designer]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[scraping]]></category>
		<category><![CDATA[screencasts]]></category>

		<guid isPermaLink="false">http://janbogaerts.name/index.php/2011/11/13/scraping-the-internet/</guid>
		<description><![CDATA[Getting information from the internet into a chatbot’s output can be very useful at some times. Not only to show continuously changing values, like weather information, but it can potentially also be used for learning, although the latter is obviously a little trickier. Retrieving, or scraping info from the internet can be done remarkably easy [...]]]></description>
			<content:encoded><![CDATA[<p>Getting information from the internet into a chatbot’s output can be very useful at some times. Not only to show continuously changing values, like weather information, but it can potentially also be used for learning, although the latter is obviously a little trickier.</p>
<p>Retrieving, or scraping info from the internet can be done remarkably easy with the chatbot designer. Here’s a screencast of a bot that retrieves weather information from the <a href="http://googleweather.riaforge.org/" target="_blank">google weather api</a>.</p>
<div class="lyte hidef" id="WYL_ppfuKxQkSJo" style="width:640px;height:360px;"><noscript><a href="http://youtu.be/ppfuKxQkSJo"><img src="http://img.youtube.com/vi/ppfuKxQkSJo/0.jpg" alt="" width="640" height="360" /><br />Watch this video on YouTube.</a></noscript><script type="text/javascript"><!-- 
 (function(){var d=document;if(d.addEventListener){d.addEventListener('DOMContentLoaded', insert, false)}else{window.onload=insert} function insert(){if(!d.getElementById('lytescr')){lytescr=d.createElement('script');lytescr.async=true;lytescr.id='lytescr';lytescr.src='http://janbogaerts.name/wp-content/plugins/wp-youtube-lyte/lyte/lyte-min.js?wylver=0.9.2';h=d.getElementsByTagName('script')[0];h.parentNode.insertBefore(lytescr, h)}};}()) 
 --></script></div>
<p>In the video, a .net plug-in is used to retrieve information from the internet by means of XPaths. This plugin is included by default in the application. Note though that plug-ins are only supported in the pro version.  Basic users will be able to use these projects, but they can’t create or edit any patterns that rely on plug-ins. Also, plug-ins are loaded on a project by project basis. So if you want to use the scraping features in your own project, you will first need to make certain that the correct .net functions have been loaded. Once this has been set up though, all plug-ins will <a href="http://janbogaerts.name/wp-content/uploads/2011/11/Capture1.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; float: right; padding-top: 0px; border-width: 0px;" title="Capture" src="http://janbogaerts.name/wp-content/uploads/2011/11/Capture_thumb1.jpg" alt="Capture" width="396" height="212" align="right" border="0" /></a>automatically be loaded when the project is opened.</p>
<h3>Loading</h3>
<p>To load a plug-in, go to <em>view/communication channels/OS</em>. This will bring up a view like the one on the right. From here, you can load and unload dlls, classes and functions. First up is the dll. This can be loaded with one of the buttons on the toolbar. The first one gives access to the cache (dlls that have already been loaded). With the next button, you can select a file from disk. Note that, even though the ‘<em>CmdShell.dll’</em> file (which contains the scraping functions) is part of the installation, it isn’t guaranteed that it’s already loaded in cache, so you might have to select it from the ‘<em>program files/Chatbot designer pro/’</em> path. By the way, you can remove a dll by selecting it and pressing delete. Functions can be selected/deselected with the checkbox in front of the name. You can alternatively (de)select the entire class or lib at once. Notice the blue label behind each function name: this is the name that you can use in the patterns. You see, the do-patterns evaluator has no knowledge whatsoever of namespaces, classes or functions, it just knows a single name. This means that all function names should be unique across a single project. If you try to enter a duplicate name, a red box will be displayed round the newly mapped name.</p>
<p>There are quite a few functions available for scraping. Basically though, there are 3 groups: some functions to open/close web-pages, some functions to get data from those opened pages and finally the same functions that don’t require you to first open/close any files but which can do a scrape directly.</p>
<h3>Short scrapes</h3>
<p>Depending on how much data you need to retrieve, you can use one or the other technique. If there is only 1 xpath that you have to run on a page, then you can probably best use the short/direct functions that don’t require you to first open the web-page. Instead the address is supplied as an argument, together with the xpath. Here’s a list of the available quick scrapers:</p>
<table width="554" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="128"><strong>Name</strong></td>
<td valign="top" width="108"><strong>Arg 1</strong></td>
<td valign="top" width="58"><strong>Arg 2</strong></td>
<td valign="top" width="258"><strong>result</strong></td>
</tr>
<tr>
<td valign="top" width="129">ScrapeText</td>
<td valign="top" width="108">file or web path</td>
<td valign="top" width="58">XPath</td>
<td valign="top" width="258">0, 1 or more text values</td>
</tr>
<tr>
<td valign="top" width="129">ScrapeInt</td>
<td valign="top" width="108">file or web path</td>
<td valign="top" width="58">XPath</td>
<td valign="top" width="258">0, 1 or more int values</td>
</tr>
<tr>
<td valign="top" width="129">ScrapeDouble</td>
<td valign="top" width="108">file or web path</td>
<td valign="top" width="58">XPath</td>
<td valign="top" width="258">0, 1 or more floating point values</td>
</tr>
<tr>
<td valign="top" width="129">ScrapeDate</td>
<td valign="top" width="108">file or web path</td>
<td valign="top" width="58">XPath</td>
<td valign="top" width="258">0, 1 or more dates</td>
</tr>
</tbody>
</table>
<p>And a short usage example to get the temperature info from the google API for a city that’s defined in ‘<em>$place</em>’:</p>
<blockquote><p>$value = ScrapeText(&#8220;<a href="http://www.google.com/ig/api?weather=">http://www.google.com/ig/api?weather=</a>$place:interleaf(+)&#8221;, “<a href="mailto:“/xml_api_reply/weather/current_conditions/temp_c/@data">/xml_api_reply/weather/current_conditions/temp_c/@data</a>”)</p></blockquote>
<p>As you can see, the first argument specified the web-page to open. The second is an xpath to the data attribute of the ‘temp_c’ element. Note that we use ‘<em>:interleaf(+)</em>’  cause the google API expects city-names that contain multiple words to be separated with a ‘+’ like: New+York.</p>
<h3>More scraping</h3>
<p>The second scraping method is primarily useful if you need to run multiple xpaths on the same content. In this case, it’s far more economical to first retrieve the page, run all the queries on the cached file and finally, when done, release it again. This can be accomplished with the remaining scrape functions.</p>
<p>You open a file or webpage with either ‘OpenScraper’ or ‘OpenScraperHTML’. The first works on xml content, the second on html. That is, the second will convert html to xml so that the xpath can be run on it. Both return an integer that needs to be used in subsequent calls. Basically, the integer replaces the filename as a reference. It allows you to have multiple files open and to have the system run multi-threaded and let it serve multiple people at the same time.</p>
<p>The scraping functions themselves are almost identical as the quick versions, except that they take an integer as first argument instead of a path. Other then that, usage is exactly the same, with the same types: one for text, integers, doubles and dates.</p>
<p>Once you are done with the file, you have to call ‘CloseScraper’ with, as argument, the integer that was returned by ‘OpenScraper(HTML)’, so that resources can be cleaned up. This is important, if you forget to do this, the system will eventually buckle, crack and give up.<br />
In a normal usage situation, you would do a short salvo: open a page, do a few scrapes and close it again, all in 1 block, but this is not a requirement, you can keep the page open across multiple inputs. As long as you maintain a reference to the scraper (the integer) somewhere in memory so that you don’t loose track of it.</p>
<h3>Html scraping</h3>
<p>As already mentioned, html scraping is done by first converting the page into xml before the xpath is executed. This conversion can cause some ‘changes’ in the structure of the file. In other words, the path that you would calculate, based on the html file might not be correct for the xml version. This means that you best build your xpaths based on the xml version of the HTML pages.</p>
<p>The conversion routine that’s internally used by the chatbot designer is based on the <a href="http://developer.mindtouch.com/SgmlReader" target="_blank">SGMLReader</a> library. This provides a command-line tool to manually convert html to xml files. This can be very useful for building the correct query. I’ve included a direct download for the <a href="http://www.janbogaerts.name/files/sgmlreader.zip" target="_blank">command line html to xml conversion tool</a>. Here’s a short description on how to use it (taken from the original documentation):</p>
<blockquote><p>sgmlreader &lt;options&gt; [InputUri] [OutputFile]</p></blockquote>
<table width="811" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="113">-e &#8220;file&#8221;</td>
<td valign="top" width="696">Specifies a file to write error output to. The default is to generate no errors. The special name &#8220;$stderr&#8221; redirects errors to stderr output stream.</td>
</tr>
<tr>
<td valign="top" width="115">-proxy &#8220;server&#8221;</td>
<td valign="top" width="695">Specifies the proxy server to use to fetch DTD&#8217;s through the fire wall.</td>
</tr>
<tr>
<td valign="top" width="116">-html</td>
<td valign="top" width="694">Specifies that the input is HTML.</td>
</tr>
<tr>
<td valign="top" width="117">-dtd &#8220;uri&#8221;</td>
<td valign="top" width="693">Specifies some other SGML DTD.</td>
</tr>
<tr>
<td valign="top" width="118">-base</td>
<td valign="top" width="692">Add an HTML base tag to the output.</td>
</tr>
<tr>
<td valign="top" width="119">-pretty</td>
<td valign="top" width="691">Pretty print the output.</td>
</tr>
<tr>
<td valign="top" width="120">-encoding name</td>
<td valign="top" width="690">Specify an encoding for the output file (default UTF-8)</td>
</tr>
<tr>
<td valign="top" width="121">-noxml</td>
<td valign="top" width="689">Stops generation of XML declaration in output.</td>
</tr>
<tr>
<td valign="top" width="122">-doctype</td>
<td valign="top" width="688">Copy &lt;!DOCTYPE tag to the output.</td>
</tr>
<tr>
<td valign="top" width="123">InputUri</td>
<td valign="top" width="687">The input file name or URL. Default is stdin. If this is a local file name then it also supports wildcards.</td>
</tr>
<tr>
<td valign="top" width="124">OutputFile</td>
<td valign="top" width="686">The optional output file name. Default is stdout. If the InputUri contains wildcards then this just specifies the output file extension, the default being &#8220;.xml&#8221;.</td>
</tr>
</tbody>
</table>
<p><strong>Examples: </strong></p>
<blockquote><p>sgmlreader -html *.htm *.xml<br />
Converts all .htm files to corresponding .xml files using the built in HTML DTD.</p></blockquote>
<blockquote><p>sgmlreader -html http://www.msn.com -proxy myproxy:80 msn.xml<br />
Converts all the MSN home page to XML storing the result in the local file &#8220;msn.xml&#8221;.</p></blockquote>
<blockquote><p>sgmlreader -dtd ofx160.dtd test.ofx ofx.xml<br />
Converts the given OFX file to XML using the SGML DTD &#8220;ofx160.dtd&#8221; specified in the test.ofx file.</p></blockquote>
<h3>Building an XPath</h3>
<p>Once you have your xml file, getting the xpath to the element that you want can still be a little challenging. Html files simply aren’t designed with this type of usage in mind (and hey, if it can be easier for xml files, why not). Enter <a href="http://getfirebug.com/" target="_blank">FireBug</a>, an add-on for <a href="http://www.mozilla.org/" target="_blank">Firefox</a> that allows developers to get a closer look at the html…. Or xml. After you have installed firebug and loaded up the xml file into firefox, go to <em>tools/Web developer/Firebug/Open firebug</em> so that you can see the debug panel. In this panel, select the element that you which to query, open the context menu and select ‘<em>copy XPath</em>’. And that’s it, simply paste this path in the chatbot designer and your done.</p>
 <img src="http://janbogaerts.name/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=721" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://janbogaerts.name/index.php/2011/11/13/scraping-the-internet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.net integration</title>
		<link>http://janbogaerts.name/index.php/2011/09/18/net-integration/</link>
		<comments>http://janbogaerts.name/index.php/2011/09/18/net-integration/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 19:05:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[chatbot designer]]></category>
		<category><![CDATA[demos]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[screencasts]]></category>

		<guid isPermaLink="false">http://janbogaerts.name/index.php/2011/09/18/net-integration/</guid>
		<description><![CDATA[A final pre-release video on how you can call .net functions from within your chatbot. The idea behind this feature is to allow you to extend your chatbot with custom features. This will only be available in the pro version though. Note: the video is best viewed in max resolution and full screen to see [...]]]></description>
			<content:encoded><![CDATA[<p>A final pre-release video on how you can call .net functions from within your chatbot. The idea behind this feature is to allow you to extend your chatbot with custom features. This will only be available in the pro version though.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:415e3a0d-8f49-45d3-98b9-42988e60a2fa" class="wlWriterEditableSmartContent">
<div id="3bfffcf4-b369-4e76-bc2b-a699869d4486" style="margin: 0px; padding: 0px; display: inline;">
<div><a href="http://www.youtube.com/watch?v=Hp51R0xJFL4" target="_new"><img src="http://janbogaerts.name/wp-content/uploads/2011/09/videode545cae90f8.jpg" style="border-style: none" galleryimg="no" onload="var downlevelDiv = document.getElementById('3bfffcf4-b369-4e76-bc2b-a699869d4486'); downlevelDiv.innerHTML = &quot;&lt;div&gt;&lt;object width=\&quot;448\&quot; height=\&quot;252\&quot;&gt;&lt;param name=\&quot;movie\&quot; value=\&quot;http://www.youtube.com/v/Hp51R0xJFL4?hl=en&amp;hd=1\&quot;&gt;&lt;\/param&gt;&lt;embed src=\&quot;http://www.youtube.com/v/Hp51R0xJFL4?hl=en&amp;hd=1\&quot; type=\&quot;application/x-shockwave-flash\&quot; width=\&quot;448\&quot; height=\&quot;252\&quot;&gt;&lt;\/embed&gt;&lt;\/object&gt;&lt;\/div&gt;&quot;;" alt=""></a></div>
</div>
</div>
<p>Note: the video is best viewed in max resolution and  full screen to see all the details.</p>
 <img src="http://janbogaerts.name/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=657" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://janbogaerts.name/index.php/2011/09/18/net-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Structured editors: a first impression</title>
		<link>http://janbogaerts.name/index.php/2010/12/20/structured-editors-a-first-impression/</link>
		<comments>http://janbogaerts.name/index.php/2010/12/20/structured-editors-a-first-impression/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 15:58:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[code editor]]></category>
		<category><![CDATA[code images]]></category>
		<category><![CDATA[designers]]></category>
		<category><![CDATA[editing]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[structured editor]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://janbogaerts.name/index.php/2010/12/20/structured-editors-a-first-impression/</guid>
		<description><![CDATA[For a while now, I’ve been working fairly intensely with the designer and it’s many structured editors. Long enough for me to get a feeling for them and find a good rhythm in working with them. So I thought it perhaps time to put down my experiences and ideas for future improvements. To tell you [...]]]></description>
			<content:encoded><![CDATA[<p>For a while now, I’ve been working fairly intensely with the designer and it’s many structured editors. Long enough for me to get a feeling for them and find a good rhythm in working with them. So I thought it perhaps time to put down my experiences and ideas for future improvements.<br />
To tell you the  truth, I took a big risk when I decided to make all the editors, including the one for code, as <a href="http://en.wikipedia.org/wiki/Structure_editor" target="_blank">structured editors</a> (aka not text-based). The reasons are simple:</p>
<ul>
<li>I had never made something like that, while I had plenty of experience <a href="http://users.telenet.be/GeneCompiler/" target="_blank">designing languages</a>,</li>
<li>I didn’t really know what the end product would look like or how it would behave,</li>
<li>and apart from some ‘UML designers’ that render classes, I had never used such a thing for editing code myself.</li>
</ul>
<p>So then, what made me decide to use this approach instead of the more conventional and traditional way of using text?  First of, a major part of the answer lies in the previous statement <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" src="http://janbogaerts.name/wp-content/uploads/2010/12/wlEmoticon-winkingsmile.png" alt="Winking smile" /> . Other reasons were:</p>
<ul>
<li>Guided editors (can) lower the entrance level, when done properly (something I needed,… seriously).</li>
<li>I new I would be needing some good debuggers (lessons learned!!). I could try and incorporate these into some existing editors, or turn out one of my own. At the time, it seemed a better idea to have full control from top to bottom, if I wanted to do this properly.</li>
<li>I had a bit of experience working in WPF, which gave me some confidence that it was possible.</li>
<li>Also, I came across this, <a href="http://blogs.msdn.com/b/kirillosenkov/archive/2009/09/08/first-videos-of-the-structured-editor-prototype.aspx" target="_blank">rather serious attempt at structured editors </a>(originally for C#), which raised my hopes as well.</li>
<li>Did I already mention you that I was hoping this would make things a bit simpler for other people to understand?</li>
</ul>
<p>In the end, it turns out I am glad I decided to use this approach, though not exactly for the reasons as previously stated.<a href="http://janbogaerts.name/wp-content/uploads/2010/12/image.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; float: right; padding-top: 0px; border-width: 0px;" title="image" src="http://janbogaerts.name/wp-content/uploads/2010/12/image_thumb.png" border="0" alt="image" width="111" height="142" align="right" /></a> Except perhaps for the debugging, which really was fairly easy to implement this way. No, the thing that convinced me was the way that it changes how you program. This didn’t happen over night, I only began noticing this the last couple of months, after some 1,5 years of (trying to) program this way.<br />
So what changed: well, over time, when I needed a ‘variable’, instead of thinking ‘variable’ I began to think ‘purple’. This is a shift from thinking in words to thinking in color. The best evidence for this, came in the form of me, continually trying to put a conditional in an assignment as if it were a global (cause I thought I had picked up a global). If you look at the picture to the right, you can probably understand why I erred: the blue colors are just to close to each other.<br />
What’s more, over time I also began to think more and more in visual structures instead of ‘if-else’ or ‘while-do’. When I think about an ‘if’, I think:</p>
<p><a href="http://janbogaerts.name/wp-content/uploads/2010/12/image1.png"><img style="background-image: none; margin: 0px auto 10px; padding-left: 0px; padding-right: 0px; display: block; float: none; padding-top: 0px; border-width: 0px;" title="image" src="http://janbogaerts.name/wp-content/uploads/2010/12/image_thumb1.png" border="0" alt="image" width="461" height="155" /></a> In short, when programming, I am thinking more and more in terms of: blue square, red hexagon, white circle with line below (the conditional part),… Or in other words, it feels as if I am programming like building with <a href="http://www.lego.com/en-gb/default.aspx" target="_blank">Lego</a> blocks!!! <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://janbogaerts.name/wp-content/uploads/2010/12/wlEmoticon-smile.png" alt="Smile" /><br />
I can’t explain exactly how or why this is, but it appears to free the mind for thinking about other stuff. At times, I find myself, just mindlessly putting blocks together to build up the picture that I had previously constructed in my head.  Very pleasing.</p>
<p>So, as a first try, I am very happy with the result, well enough for me to continue this path, and with some minor corrections here and there, keep the design. That is not to say there isn’t room for improvement, I have bucket-loads already of those, just not the time, so most of these will not be for the near future.  Others might be implemented sooner, depending on needs.</p>
<p>Basically, most of the concerns are centered round work speed (the number of movements and clicks required for an operation), maintainability and overview:</p>
<h4>Speed</h4>
<ul>
<li>To start with, the toolbox needs some redesign. I currently have 2 pages: one for general items, and a separate tab for all the instructions. I find myself continually switching between the 2, which is time consuming and unnecessary. The solution is simple: split them up in separate toolboxes.</li>
<li>The toolbox currently only supports drag-drop operations. So to get 5 objects of the same type, you need to perform 5 drags. Better would be to have a ‘paint’ tool, like graphical apps, and many (UML) designers have.</li>
<li>The code designer really could use some more keyboard support, so it can be used like a regular text editor (sort of). This seems a logical next step to do, just haven’t gotten there yet.</li>
<li>I have been thinking a lot about using WPF’s new <a href="http://www.davidezordan.net/blog/?p=1136" target="_blank">multi-touch libraries</a> to add support for using 2 mice while coding. I don’t really make use of the left hand during the GUI coding, apart from the occasional copy/paste or editing a label. At times, I could definitely work with 2 hands at the same time. It’s a bit like using both hands for searching and placing blocks.<br />
I had also thought about using this new <a href="http://www.xbox.com/en-GB/kinect" target="_blank">kinect</a> toy, which appears to have been <a href="http://www.engadget.com/2010/11/16/kinect-hack-explained-follow-along-at-home-guide-lets-you-rever/" target="_blank">hacked</a> already for PC usage. This would even resemble more like building with Lego (or like <a href="http://singularityhub.com/2010/12/10/mit-uses-xbox-kinect-to-create-cheap-minority-report-interface-video/" target="_blank">Tom cruise is doing in Minority report</a>) . But then I figured: ok how would you feel after 2 weeks of keeping  your arms up in the air? Ok, I don’t know how I’d feel after 2 weeks like that, but my shoulders and neck definitely do!!!<br />
So that plan was canceled.</li>
</ul>
<h4>Overview</h4>
<ul>
<li>As I’ve previously mentioned, I often simply recreate the picture that’s already in my head. The annoying thing is that the designer only shows a small part of the object (algorithm) that I’m working on, while at times I have more a need for a birds view approach. That’s why I added the zoom support, but more can be done such as:
<ul>
<li>make the code templates (the drawings) a bit smaller. I’m no good at designing, which shows.</li>
<li>provide a bread-crumb like ability (for drilling down and going back up again), much like the windows file explorer provides using it’s breadcrumb approach for directories.  I could use this for sub blocks.</li>
<li>See what I can do about providing support for multiple screens.</li>
<li>Buy a new big sized monitor, but given the massive resources at my disposal, that’s not an option <img class="wlEmoticon wlEmoticon-sadsmile" style="border-style: none;" src="http://janbogaerts.name/wp-content/uploads/2010/12/wlEmoticon-sadsmile.png" alt="Sad smile" /></li>
</ul>
</li>
<li>Also previously stated: some of the colors can use a little tuning, the same perhaps for some shapes, to make them more distinguishable from each other.</li>
<li>Currently, the drop area for the arguments is displayed as a simple, single square. The thing is: the argument requirements are known for each instruction, so it’s perfectly possible to display a custom set of boxes, with correct labels, for each instruction. This, by the way, would also free some space, since no drop area needs to be shown when all arguments are provided.</li>
<li>I could also try to implement some sort of 3D-view on the network model, but I think I’ll need to extend my skill-set for that one.</li>
</ul>
<h4>Maintainability</h4>
<p>The single major issue I have with code maintainability is concerning documentation. I added support for this by allowing to add some ‘rich-text’ string to each neuron. The idea being that you’d put all the comments concerning what’s going on, in there. Unfortunately, it doesn’t really work very well for code documentation because:</p>
<ul>
<li>neurons can be reused. This is different compared to regular text code: when this is compiled, each line of code will get it’s own output (or better, each compiled instruction corresponds with exactly 1 location within the text). With this neural network however, things are a bit different: it’s perfectly possible to use the same assignment in 2 (or more) different places. This is something I do extensively, by the way, to speed up coding and to keep the nr of links down.  What I noticed is this: though the code is shareable, the reason usually isn’t. I am currently solving this by stacking the different comments in the same text-blob, when needed. But better solutions are possible.</li>
<li>I also find it annoying having to select an object in order to see it’s comments within the code view. It appears to be easier/better when you can quickly scan a document for all comments and read the one you need, without thinking about selection.</li>
</ul>
<p>To solve this, I have been thinking about adding support for comments within the ‘project’ documents. These would maintain and display (as call-out balloons) all the comments for the neurons that they contain. The location of the comments would be determined by the comments themselves, so they can be floating, closest to the neuron that they are attached to. This would also allow me to display the comments, even if the actual neurons aren’t visible, but collapsed.</p>
<h4>Final note</h4>
<p>As a final note, for those who would like to build their own structured editor in WPF, perhaps a word of advice: <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.aspx" target="_blank">stay away from</a> ItemsControl or any of it’s descendants. The paradigm sounds grate: manage a list of items and display them any way you want through styling and templates. What’s not mentioned is that this only works for 10 objects or so. Any more, and your app slows down to a crawl or worse: crashes just as bad as the good old win32 apps would, perhaps even worse at times. Instead, go lower level: inherit from panel and roll out your own Measure/Arrange or go even further down and overwrite the rendering routines.</p>
 <img src="http://janbogaerts.name/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=513" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://janbogaerts.name/index.php/2010/12/20/structured-editors-a-first-impression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF: a fast TreeView</title>
		<link>http://janbogaerts.name/index.php/2010/09/09/wpf-a-fast-treeview/</link>
		<comments>http://janbogaerts.name/index.php/2010/09/09/wpf-a-fast-treeview/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 12:29:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[treeview]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://janbogaerts.name/index.php/2010/09/09/wpf-a-fast-treeview/</guid>
		<description><![CDATA[An introduction on creating proper UI virtualization in WPF. It describes a technique to create treeviews in WPF that are able to display any amount of data while maintaining scroll speed and using a minimum of memory.]]></description>
			<content:encoded><![CDATA[<p>Are you getting sick already of WPF’s inability to handle large amounts of data? Well, I am,… definitely. After some final trials with the thesaurus (displayed in a tree), I gave up and decided to write my own virtualizing Treeview. Why? Here’s why:</p>
<ul>
<li>Scroll &amp; load speed: Even with full virtualization turned on, scrolling crawls almost to a halt when you have 60 000+ root items and a few of them are expanded some levels down the tree. The same for loading large lists.</li>
<li>Memory usage: probably related with the previous item, in short: kaboem!!!</li>
<li>BringIntoView: Here’s the killer, when virtualization is turned on, and the UI TreeViewIem hasn’t been rendered yet, you can’t bring it into view. Translated: you can’t do a search and show the found items in large trees, only in small trees (go figure).</li>
</ul>
<p>Note about my test data:  The thesaurus demo contains about 100 000 words (syn-sets actually), almost all of which have multiple relationships, so  in total, there are +500 000 nodes in the tree.</p>
<p>Ok,… and how do you fix this? Well here’s how I did it:</p>
<h4>Container rendering</h4>
<p>Virtualization means that you only render the UI elements that are currently visible, and not the whole tree (or a large part like microsoft does). This means that, for each UI object that got rendered, you somehow need to keep track of the data position in the tree. I do this by using 2 cursors: one for the first and another for the last visible element. This cursor is nothing more than a list of indexes into the tree.</p>
<p>All items in between those 2 cursors are flattened out (by rendering UI elements for them). The nr of indexes (or nr of parents) for each item, is used as the level for the UI element. This determines the amount of indentation to the right that is applied to the UI element.</p>
<p>When the user scrolls down, the bottom cursor is updated (advanced by the amount that the user scrolled). This is a basic tree walking algorithm. From this bottom index, we render objects while going up the tree until the panel is full (again, the same tree walking algorithm). The index path of the new top item becomes the new top cursor. The same technique is used to scroll up, but instead, you start from the top cursor and fill downwards.</p>
<p><em>Remark: Watch out while calculating the scroll difference: The scrollbar value is usually a double while we only consume integer values, so there might be some left over in the scroll difference which has to be consumed the next time you calculate the dif.</em></p>
<p>Of course, this technique only works if the TreeView has some knowledge of the data structure, how else can it find the children of the root items and see if they are expanded or not? This requires an interface. Here’s how mine looks like:</p>
<pre class="code"><span style="color: blue;">   public interface </span><span style="color: #2b91af;">ITreeViewItem
   </span>{<span style="color: gray;">
      </span><span style="color: blue;">bool </span>IsExpanded { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<span style="color: gray;">
      </span><span style="color: blue;">bool </span>IsSelected { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<span style="color: gray;">
      </span><span style="color: blue;">bool </span>HasChildren { <span style="color: blue;">get</span>; }<span style="color: gray;">
      </span><span style="color: #2b91af;">IList </span>TreeItems { <span style="color: blue;">get</span>; }<span style="color: gray;">
      </span><span style="color: #2b91af;">ITreeViewPanelItem </span>ParentTreeItem { <span style="color: blue;">get</span>; }
<span style="color: gray;">      </span><span style="color: blue;">bool </span>NeedsBringIntoView { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }
   }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Each tree node should implement this interface so that the TreeView can properly traverse the tree. A few properties are mostly for the visual parts, like ‘IsSelected’ or ’HasChildren’ (to display the toggle button). The last property is perhaps a bit of an odd one: ‘NeedsBringIntoView’. It’s a quick method to let the Tree know that an element needs to be brought into the viewable area. You could also use a function on the TreeView (like microsoft does), but then you are forced to go find the UI element from your search code to bring the item into view, which I wanted to avoid.</p>
<p>Using this technique, you do create and destroy a lot of containers since each time the user scrolls, the entire visible area is re-rendered. To minimize the impact of this on the garbage collector, it’s probably best to use some recycling scheme. This doesn’t have to be fancy: a simple queue to put the items in when clearing the list which can be consumed again when rendering the containers. I chose a queue since it gives best chances to reassign the same container to the same data object when possible, which minimizes the impact of re-rendering on the binding system.</p>
<h4>Events</h4>
<p>The second important thing for virtualized TreeViews, is the event system. You can not simply go and hook up event handlers to every data element. This would blow up the memory. Also, you’d have to write a lot of code to keep track of those events as data objects are being created and destroyed (trees of such a size can only work if you combine UI virtualization with data virtualization, but that’s an entire subject all together). On the other hand, events are VERY important to get UI virtualization working for keeping track of the maximum scroll count, tree nodes that get expanded/collapsed, objects that need to be brought into view, and UI elements that need to be updated.</p>
<p>Are you seeing the bubbles already? Yep: use bubbling events, like WPF does. The only problem: that doesn’t exist for regular objects, it’s only available in the WPF world. You could inherit all your objects from <em>DependencyObject</em>, but with 200 0000 objects in memory, that somehow becomes bloated. Better to roll out your own sleek, mean and fast event mechanism, which isn’t hard at all to do. Here’s a little sample code to bubble events up a tree:</p>
<pre class="code"><span style="color: blue;">public static void </span>OnPropertyChanged(<span style="color: #2b91af;">IOnBubblingChanged </span>sender, <span style="color: #2b91af;">BubblingPropertyChangedEventArgs </span>e)
{
   <span style="color: blue;">while </span>(sender != <span style="color: blue;">null</span>)                                  <span style="color: green;">//use a while loop to avoid recursive calls.
   </span>{
      sender.OnBubblingPropertyChanged(e);
      <span style="color: #2b91af;">IOwnedObject </span>iOwned = sender <span style="color: blue;">as </span><span style="color: #2b91af;">IOwnedObject</span>;
      <span style="color: blue;">if </span>(iOwned != <span style="color: blue;">null</span>)
         sender = iOwned.Owner <span style="color: blue;">as </span><span style="color: #2b91af;">IOnBubblingChanged</span>;
      <span style="color: blue;">else
         </span>sender = <span style="color: blue;">null</span>;                                    <span style="color: green;">//need to make the loop stop
   </span>}
}</pre>
<p>This function is called whenever a property on a tree item is changed. As you can see, a lot of interfaces are at work here. <em>IOnBubblingChanged</em> defines a function that can be called which will raise the event. IOwnedObject is one of my core interfaces for all objects that can be ‘owned’ by another object. This maps to the ‘<em>ParentTreeItem</em>’ property of the first <em>ITreeViewItem</em> interface.</p>
<p>A similar thing needs to be done for the <em>CollectionChanged</em> events. A remark on the ‘reset collection’ event: make certain that you can pass along the list of items that got cleared, otherwise the TreeView will have a hard time figuring out exactly how much the count needs to be decreased (were any of the removed items expanded?). The default WPF <em>NotifyCollectionChanged</em> event doesn’t do that, so you can’t simply use it’s event arguments.</p>
<p>With this type of bubbling event system, it’s probably best to work with some kind of ‘root’ object that defines the events for the property and collection changes in the entire tree. Again a nice job for an interface, I suppose. This root interface can be used as the <em>ItemsSource</em> for the treeview instead of a list, like WPF does. This way, you can have lots of root objects without overtaxing the .net event management system.</p>
<p>Using this technique, you can make Treeviews that aren’t only fast to load and scroll, but also use very little memory. I am silently hoping that microsoft will eventually pick up on this and begin implementing proper UI virtualization in the coming versions of WPF (thus relieving me from the burden). In the mean time, I guess we are left to roll out our own stuff.</p>
 <img src="http://janbogaerts.name/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=449" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://janbogaerts.name/index.php/2010/09/09/wpf-a-fast-treeview/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AICI calling .Net</title>
		<link>http://janbogaerts.name/index.php/2010/07/11/aici-calling-net/</link>
		<comments>http://janbogaerts.name/index.php/2010/07/11/aici-calling-net/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 14:33:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AICI]]></category>
		<category><![CDATA[Conversations]]></category>
		<category><![CDATA[N²D]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Updates]]></category>

		<guid isPermaLink="false">http://janbogaerts.name/index.php/2010/07/11/aici-calling-net/</guid>
		<description><![CDATA[Note: Deprecated! The thunk to .Net is finally working: So it’s now possible to call static functions that take value types as argument and/or as return type.  In this example, I am calling the standard System.IO.File.Copy function to copy a file on my disk. Exceptions are also supported, as you can see from the first [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><em><strong>Note: Deprecated</strong></em>!</p></blockquote>
<p>The thunk to .Net is finally working:</p>
<p><a href="http://janbogaerts.name/wp-content/uploads/2010/07/image1.png"><img style="margin: 0px auto; display: block; float: none; border-width: 0px;" title="image" src="http://janbogaerts.name/wp-content/uploads/2010/07/image_thumb1.png" border="0" alt="image" width="409" height="76" /></a></p>
<p>So it’s now possible to call static functions that take value types as argument and/or as return type.  In this example, I am calling the standard <em>System.IO.File.Copy</em> function to copy a file on my disk. Exceptions are also supported, as you can see from the first line, when I am trying to copy a non existing file. The output comes from the exception generated by the copy. Note that you can specify the arguments in different ways. In this example, I am using the ‘to’ word. ‘From’ would also be recognized. Both determine the extraction order of the arguments.</p>
<p>At the moment, I have hardcoded this extraction of the function arguments for the ‘copy-verb’ manually. The idea is to change it to something more general that can work for any .net function using some meta data of the function (like which neuron to send to which output, how to recognize the arguments, how many arguments,…). I’m not there yet though. First some finishing touches to the designer, so I can trace some neuron/memory leaks. After that I’ll probably do a new release, so you can play a bit.</p>
<p>Oh, and it’s still way to hot outside <img src='http://janbogaerts.name/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
 <img src="http://janbogaerts.name/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=306" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://janbogaerts.name/index.php/2010/07/11/aici-calling-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF is getting under my skin</title>
		<link>http://janbogaerts.name/index.php/2010/02/24/wpf-is-getting-under-my-skin/</link>
		<comments>http://janbogaerts.name/index.php/2010/02/24/wpf-is-getting-under-my-skin/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 12:58:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[N²D]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://janbogaerts.name/index.php/2010/02/24/wpf-is-getting-under-my-skin/</guid>
		<description><![CDATA[I have been fighting the WPF model all the way during the development of NND. And it is wearing me down. Latest problem: the updated selection box for frame element filters doesn’t want to get focus, making it impossible to use the keyboard. I guess the new release will have to wait until I can [...]]]></description>
			<content:encoded><![CDATA[<p>I have been fighting the WPF model all the way during the development of NND. And it is wearing me down. Latest problem: the updated selection box for frame element filters doesn’t want to get focus, making it impossible to use the keyboard. I guess the new release will have to wait until I can get this fixed. Bummer.</p>
<p><a href="http://janbogaerts.name/wp-content/uploads/2010/02/image1.png"><img style="margin: 0px; display: inline; border-width: 0px;" title="image" src="http://janbogaerts.name/wp-content/uploads/2010/02/image_thumb1.png" alt="image" width="758" height="728" border="0" /></a></p>
 <img src="http://janbogaerts.name/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=191" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://janbogaerts.name/index.php/2010/02/24/wpf-is-getting-under-my-skin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

