/**
  * * Executes the CycProxyFactory thread and processes the the (cyc-to-agent-manager-init
  * <image-id> <base-port>) message.
  */
 public void run() {
   Log.current.println("Begin CycProxyFactory thread");
   try {
     cycConnection = new CycConnection(cfaslSocket);
   } catch (Exception e) {
     Log.current.println("Exception creating CycConnection " + e.getMessage());
     throw new RuntimeException("Exception creating CycConnection: " + e.getMessage());
   }
   CycList cycToAgentManagerInitMessage = null;
   try {
     // cycConnection.traceOnDetailed();
     cycToAgentManagerInitMessage = cycConnection.receiveBinaryApiRequest();
   } catch (Exception e) {
     Log.current.println("Exception with CycConnection: " + e.getMessage());
     return;
   }
   if (!cycToAgentManagerInitMessage
       .first()
       .equals(CycObjectFactory.makeCycSymbol("cyc-to-agent-manager-init"))) {
     Log.current.println("Invalid initialization message: " + cycToAgentManagerInitMessage);
     return;
   }
   String cycImageId = (String) cycToAgentManagerInitMessage.second();
   int basePort = ((Integer) cycToAgentManagerInitMessage.third()).intValue();
   String myAgentName = "cyc-api-service-" + cycImageId;
   CycProxy cycProxy = new CycProxy(myAgentName, verbosity);
   cycProxy.agentsCycConnection = cycConnection;
   CycAgentInfo cycAgentInfo = new CycAgentInfo(basePort, cycImageId, cycProxy);
   AgentManager.cycAgents.put(myAgentName, cycAgentInfo);
   cycProxy.initializeAgentCommunity();
   cycProxy.handleMessagesFromCyc();
 }
  /**
   * Provides the main method for an EELD DAML export.
   *
   * @parameter args the optional command line arguments
   */
  public static void main(String[] args) {
    try {
      cycAccess =
          new CycAccess(
              CycConnection.DEFAULT_HOSTNAME,
              CycConnection.DEFAULT_BASE_PORT,
              CycConnection.DEFAULT_COMMUNICATION_MODE,
              CycAccess.DEFAULT_CONNECTION);
      /*
          new CycAccess(CycConnection.DEFAULT_HOSTNAME,
                        3620,
                        CycConnection.DEFAULT_COMMUNICATION_MODE,
                        CycAccess.DEFAULT_CONNECTION);
      */
      ExportDaml exportDaml = new ExportDaml(cycAccess);
      exportDaml.verbosity = ExportDaml.DEFAULT_VERBOSITY;
      // exportDaml.verbosity = 9;

      String choice = "eeld-core";
      if (args.length > 0) choice = args[0];

      Log.current.println("Choosing KB selection: " + choice);
      // These require the Cycorp IKB or full KB to work as setup below.
      if (choice.equals("all")) {
        exportDaml.includeUpwardClosure = false;
        exportDaml.title = "Open Cyc Ontology";
        exportDaml.outputPath = "open-cyc.daml";
        exportDaml.export(ExportDaml.EXPORT_ENTIRE_KB);
      }
      if (choice.equals("eeld-core")) {
        exportDaml.cycKbSubsetCollectionGuid = eeldSharedOntologyCoreConstantGuid;
        exportDaml.cycKbSubsetFilterGuid = ikbConstantGuid;
        exportDaml.title = "EELD Shared Core Ontology";
        exportDaml.outputPath = "eeld-shared-core-ontology.daml";
        exportDaml.export(ExportDaml.EXPORT_KB_SUBSET);
      } else if (choice.equals("eeld")) {
        exportDaml.cycKbSubsetCollectionGuid = eeldSharedOntologyConstantGuid;
        exportDaml.cycKbSubsetFilterGuid = ikbConstantGuid;
        exportDaml.title = "EELD Shared Ontology";
        exportDaml.outputPath = "eeld-shared-ontology.daml";
        CycList kbSubsetCollections = new CycList();
        kbSubsetCollections.add(cycAccess.getKnownConstantByName("EELDSyntheticDataConstant"));
        kbSubsetCollections.add(cycAccess.getKnownConstantByName("EELDNaturalDataConstant"));
        CycList applicableBinaryPredicates =
            cycAccess.getApplicableBinaryPredicates(kbSubsetCollections);
        applicableBinaryPredicates.remove(cycAccess.isa);
        applicableBinaryPredicates = applicableBinaryPredicates.sort();
        Log.current.println(
            "applicableBinaryPredicates: \n" + applicableBinaryPredicates.cyclify());
        exportDaml.applicableBinaryPredicates = applicableBinaryPredicates;
        exportDaml.export(ExportDaml.EXPORT_KB_SUBSET);

      } else if (choice.equals("transportation-device")) {
        Guid transportationDeviceGuid =
            CycObjectFactory.makeGuid("bd58d540-9c29-11b1-9dad-c379636f7270");
        exportDaml.rootTermGuid = transportationDeviceGuid;
        exportDaml.cycKbSubsetFilterGuid = counterTerrorismConstantGuid;
        exportDaml.export(ExportDaml.EXPORT_KB_SUBSET_BELOW_TERM);
      } else {
        System.out.println("specified choice not found - " + choice);
        System.exit(1);
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }