Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - mbedward

Pages: [1]
1
Java / Re: Direct entry of data into tables
« on: March 13, 2014, 00:15:30  »
Thanks Frank - that makes sense

2
Java / Direct entry of data into tables
« on: March 12, 2014, 08:53:56  »
The API manual states that direct entry of data into a node's table should be followed by a call to a function tonotify the node that data have changed (p40, C function h_node_touch_table).

There doesn't seem to be an equivalent method in the Java API. Is notification not required or am I missing it ?

cheers
Michael

3
Java / Scala example: loading network from a set of oobn files
« on: March 05, 2014, 05:42:27  »
Hi all,

I really like code snippets and usage examples when I'm trying to learn a new API. So in case it is useful to others, here is the code for a minimal Scala app to load an object oriented network from a set of oobn files in a given working directory.

Warning: first attempt so beware of bugs.

Michael


Code: [Select]
package fdr.bn

import COM.hugin.HAPI.ClassCollection
import COM.hugin.HAPI.ClassParseListener
import COM.hugin.HAPI.Domain
import COM.hugin.HAPI.ExceptionHugin
import COM.hugin.HAPI.Node


/** Minimal test app to load an OO network. */
object TestApp extends App {

  val workingDir = "c:/michael/hugin/api-testing"
  val topClass = "model"

  OOBNLoader.load(workingDir, topClass) match {
    case Some(domain) =>
      println("loader returned a domain")
      
      // All we do in this test app is retrieve the network nodes and
      // print their names
      import scala.collection.JavaConverters._
      val nodes = domain.getNodes().asScala map (_.asInstanceOf[Node])
      nodes foreach (node => println(node.getName()))
      
      domain.delete()
      
    case None =>
      println("loader returned nothing")
  }
  
}


/**
 * Used to load a set of oobn files for an object oriented network
 * from a given working directory and create a Domain object.
 */
class OOBNLoader(dir: String) {

  val workingDir =
    if (dir.endsWith("/")) dir
    else dir + "/"

  def nameToPath(className: String) =
    workingDir + className + ".oobn"

  /**
   * Loads a network, given the name of the top class,
   * and returns an Option[Domain].
   */
  @throws(classOf[ExceptionHugin])
  def load(topClassName: String): Option[Domain] = {
    val cc = new ClassCollection
    try {
      val parseListener = new ParseListener(workingDir)

      val topFile = nameToPath(topClassName)
      cc.parseClasses(topFile, parseListener)
      val top = cc.getClassByName(topClassName)

      if (top == null) {
        println("Class not found: " + topClassName)
        None
      } else {
        Some(top.createDomain())
      }

    } finally {
      cc.delete()
    }
  }

  /**
   * In the Hugin Java API, a ClassParseListener is responsible for
   * loading a given network class. This implementation takes an
   * argument for the working directory which is assumed to contain
   * all of the class files (.oobn) associated with a network.
   */
  class ParseListener(dir: String) extends ClassParseListener {

    def parseError(line: Int, msg: String) {
      println("Parse error in line " + line + ": " + msg);
    }

    def insertClass(className: String, cc: ClassCollection) {
      try {
        cc.parseClasses(nameToPath(className), this);
      } catch {
        case e: Exception =>
          println("Parsing failed: " + e.getMessage());
      }
    }
  }
}

/**
 * Companion object with convenience methods.
 */
object OOBNLoader {
  /** Creates a loader for a given working directory. */
  def apply(dir: String) = new OOBNLoader(dir)
  
  /** Loads a network given a working directory and top class name. */
  def load(dir: String, topClass: String): Option[Domain] =
    OOBNLoader(dir).load(topClass)
}


4
Thanks for the right-click tip Martin. I'm sure that will come in handy.

Michael

5
Java / Re: Java API with Scala / SBT
« on: March 05, 2014, 05:21:23  »
Thanks very much Nicolaj. Before seeing your reply I discovered that I could also set the dll location via project properties -> Java Build Path -> Native library location. However, your method seems a lot clearer.

Cheers,
Michael

6
Java / Java API with Scala / SBT
« on: February 28, 2014, 00:17:39  »
Hi all,

I'd be interested to know if anyone here is using Hugin from Scala. I have just begun to explore this, using SBT as the build tool and Eclipse for editing.

After copying the Hugin api jar and dll file into the sbt project lib directory, and adding an element to my build.sbt file to recognize the dll file as an extra classpathType element, I am able to compile and run an app that loads an oobn file successfully. Unfortunately this only works when running from SBT so far. Trying to run the app from Eclipse provokes a comjplaint about the dll file not being a valid archive (zip / jar).

If anyone has experience with Hugin / Scala / SBT I'd be grateful for any tips about setting up the build environment.

Cheers,
Michael

7
A beginner question. Searched the forum and FAQ but didn't find an answer...

Working through tutorial for EM learning with the asia dataset I get the error "The state range of the node is insufficient for the chosen standard distribution". Editing asia.dat to replace the "N/A" values with empty strings fixes the problem.

The manual and online examples refer to "N/A" - is this now deprecated ?

I'm using Hugin 7.7 on Windows 7.



Pages: [1]