Beispiel #1
0
  private void ConnectKnowledgeBaseBtnMouseClicked(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_ConnectKnowledgeBaseBtnMouseClicked

    String sPrjFile = ProjectNameTF.getText().trim();
    String sLocationURI = sURI + "Location";

    Collection errors = new ArrayList();
    Date d1 = new Date();
    long l1 = d1.getTime();
    prj = Project.loadProjectFromFile(sPrjFile, errors);
    owlModel = (OWLModel) prj.getKnowledgeBase();

    kb = prj.getKnowledgeBase();
    URI uri = prj.getActiveRootURI();

    Collection colNumberOfInstance = kb.getInstances();
    lNumberOfInstance = colNumberOfInstance.size();

    Date d2 = new Date();
    long l2 = d2.getTime();
    lLoadedTime = (l2 - l1);

    theLogger.info("Connected to MySQL in " + lLoadedTime + " ms");
    theLogger.info("KB has " + lNumberOfInstance + " instances");

    LoggingAreaTA.append("Project has " + lNumberOfInstance + " in total\n");
    LoggingAreaTA.append("Project is loaded in " + lLoadedTime + " ms\n");
  } // GEN-LAST:event_ConnectKnowledgeBaseBtnMouseClicked
Beispiel #2
0
 private void BriefInfoBtnMouseClicked(
     java.awt.event.MouseEvent evt) { // GEN-FIRST:event_BriefInfoBtnMouseClicked
   // TODO add your handling code here:
   Collection colNumberOfInstance = kb.getInstances();
   long lNumberOfInstance = colNumberOfInstance.size();
   LoggingAreaTA.append("Project has " + lNumberOfInstance + " in total");
   LoggingAreaTA.append("Project is loaded in " + lLoadedTime + " ms");
 } // GEN-LAST:event_BriefInfoBtnMouseClicked
Beispiel #3
0
 public void startServer() throws Exception {
   while (true) {
     Socket s = server.accept();
     cClient.add(new ClientConn(s));
     ta.append("NEW-CLIENT " + s.getInetAddress() + ":" + s.getPort());
     ta.append("\n" + "CLIENTS-COUNT: " + cClient.size() + "\n\n");
   }
 }
Beispiel #4
0
 private static void assertEqualList(List<?> a, Collection<?> b) {
   if (a.size() == b.size()) {
     for (Object x : a) {
       if (!b.contains(x))
         throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">");
     }
     return;
   }
   throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">");
 }
Beispiel #5
0
  // get signs using an additional arg for a target rel
  private Collection<Sign> getSignsFromPredAndTargetRel(String pred, String targetRel) {

    Collection<Word> words = (Collection<Word>) _predToWords.get(pred);
    String specialTokenConst = null;

    // for robustness, when using supertagger, add words for pred sans sense index
    int dotIndex = -1;
    if (_supertagger != null
        && !Character.isDigit(pred.charAt(0))
        && // skip numbers
        (dotIndex = pred.lastIndexOf('.')) > 0
        && pred.length() > dotIndex + 1
        && pred.charAt(dotIndex + 1) != '_') // skip titles, eg Mr._Smith
    {
      String barePred = pred.substring(0, dotIndex);
      Collection<Word> barePredWords = (Collection<Word>) _predToWords.get(barePred);
      if (words == null) words = barePredWords;
      else if (barePredWords != null) {
        Set<Word> unionWords = new HashSet<Word>(words);
        unionWords.addAll(barePredWords);
        words = unionWords;
      }
    }

    if (words == null) {
      specialTokenConst = tokenizer.getSpecialTokenConstant(tokenizer.isSpecialToken(pred));
      if (specialTokenConst == null) return null;
      // lookup words with pred = special token const
      Collection<Word> specialTokenWords = (Collection<Word>) _predToWords.get(specialTokenConst);
      // replace special token const with pred
      if (specialTokenWords == null) return null;
      words = new ArrayList<Word>(specialTokenWords.size());
      for (Iterator<Word> it = specialTokenWords.iterator(); it.hasNext(); ) {
        Word stw = it.next();
        Word w = Word.createSurfaceWord(stw, pred);
        words.add(w);
      }
    }

    List<Sign> retval = new ArrayList<Sign>();
    for (Iterator<Word> it = words.iterator(); it.hasNext(); ) {
      Word w = it.next();
      try {
        SignHash signs = getSignsFromWord(w, specialTokenConst, pred, targetRel);
        retval.addAll(signs.asSignSet());
      }
      // shouldn't happen
      catch (LexException exc) {
        System.err.println("Unexpected lex exception for word " + w + ": " + exc);
      }
    }
    return retval;
  }
  /**
   * Returns compact class host.
   *
   * @param obj Object to compact.
   * @return String.
   */
  @Nullable
  public static Object compactObject(Object obj) {
    if (obj == null) return null;

    if (obj instanceof Enum) return obj.toString();

    if (obj instanceof String || obj instanceof Boolean || obj instanceof Number) return obj;

    if (obj instanceof Collection) {
      Collection col = (Collection) obj;

      Object[] res = new Object[col.size()];

      int i = 0;

      for (Object elm : col) res[i++] = compactObject(elm);

      return res;
    }

    if (obj.getClass().isArray()) {
      Class<?> arrType = obj.getClass().getComponentType();

      if (arrType.isPrimitive()) {
        if (obj instanceof boolean[]) return Arrays.toString((boolean[]) obj);
        if (obj instanceof byte[]) return Arrays.toString((byte[]) obj);
        if (obj instanceof short[]) return Arrays.toString((short[]) obj);
        if (obj instanceof int[]) return Arrays.toString((int[]) obj);
        if (obj instanceof long[]) return Arrays.toString((long[]) obj);
        if (obj instanceof float[]) return Arrays.toString((float[]) obj);
        if (obj instanceof double[]) return Arrays.toString((double[]) obj);
      }

      Object[] arr = (Object[]) obj;

      int iMax = arr.length - 1;

      StringBuilder sb = new StringBuilder("[");

      for (int i = 0; i <= iMax; i++) {
        sb.append(compactObject(arr[i]));

        if (i != iMax) sb.append(", ");
      }

      sb.append("]");

      return sb.toString();
    }

    return U.compact(obj.getClass().getName());
  }
Beispiel #7
0
  public String _toclasspath(String args[]) {
    verifyCommand(args, _toclasspathHelp, null, 2, 3);
    boolean cl = true;
    if (args.length > 2) cl = Boolean.valueOf(args[2]);

    Collection<String> names = Processor.split(args[1]);
    Collection<String> paths = new ArrayList<String>(names.size());
    for (String name : names) {
      String path = name.replace('.', '/') + (cl ? ".class" : "");
      paths.add(path);
    }
    return Processor.join(paths, ",");
  }
Beispiel #8
0
  private long InstancesCount() {

    String sIname = ClassNameTF.getText().trim();
    long lNumberOfInstance = 0;
    if (sIname.length() > 0) {
      String sClassName = ClassNameTF.getText();
      try {
        Cls cls = kb.getCls(sClassName);
        Collection colInstances = kb.getInstances(cls);
        lNumberOfInstance = colInstances.size();
      } catch (Exception e) {
        theLogger.severe("Class not found");
      }

    } else {
      try {
        Collection colInstances = kb.getInstances();
        lNumberOfInstance = colInstances.size();
      } catch (Exception e) {
        theLogger.severe("Class not found");
      }
    }
    return lNumberOfInstance;
  }
  static void loadDescriptorsFromClassPath(
      @NotNull List<IdeaPluginDescriptorImpl> result, @Nullable StartupProgress progress) {
    Collection<URL> urls = getClassLoaderUrls();
    String platformPrefix = System.getProperty(PlatformUtilsCore.PLATFORM_PREFIX_KEY);
    int i = 0;
    for (URL url : urls) {
      i++;
      if ("file".equals(url.getProtocol())) {
        File file = new File(decodeUrl(url.getFile()));

        IdeaPluginDescriptorImpl platformPluginDescriptor = null;
        if (platformPrefix != null) {
          platformPluginDescriptor = loadDescriptor(file, platformPrefix + "Plugin.xml");
          if (platformPluginDescriptor != null && !result.contains(platformPluginDescriptor)) {
            platformPluginDescriptor.setUseCoreClassLoader(true);
            result.add(platformPluginDescriptor);
          }
        }

        IdeaPluginDescriptorImpl pluginDescriptor = loadDescriptor(file, PLUGIN_XML);
        if (platformPrefix != null
            && pluginDescriptor != null
            && pluginDescriptor.getName().equals(SPECIAL_IDEA_PLUGIN)) {
          continue;
        }
        if (pluginDescriptor != null && !result.contains(pluginDescriptor)) {
          if (platformPluginDescriptor != null) {
            // if we found a regular plugin.xml in the same .jar/root as a platform-prefixed
            // descriptor, use the core loader for it too
            pluginDescriptor.setUseCoreClassLoader(true);
          }
          result.add(pluginDescriptor);
          if (progress != null) {
            progress.showProgress(
                "Plugin loaded: " + pluginDescriptor.getName(),
                PLUGINS_PROGRESS_MAX_VALUE * ((float) i / urls.size()));
          }
        }
      }
    }
  }
Beispiel #10
0
  public String _toclassname(String args[]) {
    verifyCommand(args, _toclassnameHelp, null, 2, 2);
    Collection<String> paths = Processor.split(args[1]);

    List<String> names = new ArrayList<String>(paths.size());
    for (String path : paths) {
      if (path.endsWith(".class")) {
        String name = path.substring(0, path.length() - 6).replace('/', '.');
        names.add(name);
      } else if (path.endsWith(".java")) {
        String name = path.substring(0, path.length() - 5).replace('/', '.');
        names.add(name);
      } else {
        domain.warning(
            "in toclassname, "
                + args[1]
                + " is not a class path because it does not end in .class");
      }
    }
    return Processor.join(names, ",");
  }
 /**
  * Returns all Groovy classes loaded by this class loader.
  *
  * @return all classes loaded by this class loader
  */
 public Class[] getLoadedClasses() {
   synchronized (classCache) {
     final Collection<Class> values = classCache.values();
     return values.toArray(new Class[values.size()]);
   }
 }
  /**
   * Grabs local events and detects if events was lost since last poll.
   *
   * @param ignite Target grid.
   * @param evtOrderKey Unique key to take last order key from node local map.
   * @param evtThrottleCntrKey Unique key to take throttle count from node local map.
   * @param evtTypes Event types to collect.
   * @param evtMapper Closure to map grid events to Visor data transfer objects.
   * @return Collections of node events
   */
  public static Collection<VisorGridEvent> collectEvents(
      Ignite ignite,
      String evtOrderKey,
      String evtThrottleCntrKey,
      final int[] evtTypes,
      IgniteClosure<Event, VisorGridEvent> evtMapper) {
    assert ignite != null;
    assert evtTypes != null && evtTypes.length > 0;

    ConcurrentMap<String, Long> nl = ignite.cluster().nodeLocalMap();

    final long lastOrder = getOrElse(nl, evtOrderKey, -1L);
    final long throttle = getOrElse(nl, evtThrottleCntrKey, 0L);

    // When we first time arrive onto a node to get its local events,
    // we'll grab only last those events that not older than given period to make sure we are
    // not grabbing GBs of data accidentally.
    final long notOlderThan = System.currentTimeMillis() - EVENTS_COLLECT_TIME_WINDOW;

    // Flag for detecting gaps between events.
    final AtomicBoolean lastFound = new AtomicBoolean(lastOrder < 0);

    IgnitePredicate<Event> p =
        new IgnitePredicate<Event>() {
          /** */
          private static final long serialVersionUID = 0L;

          @Override
          public boolean apply(Event e) {
            // Detects that events were lost.
            if (!lastFound.get() && (lastOrder == e.localOrder())) lastFound.set(true);

            // Retains events by lastOrder, period and type.
            return e.localOrder() > lastOrder
                && e.timestamp() > notOlderThan
                && F.contains(evtTypes, e.type());
          }
        };

    Collection<Event> evts = ignite.events().localQuery(p);

    // Update latest order in node local, if not empty.
    if (!evts.isEmpty()) {
      Event maxEvt = Collections.max(evts, EVTS_ORDER_COMPARATOR);

      nl.put(evtOrderKey, maxEvt.localOrder());
    }

    // Update throttle counter.
    if (!lastFound.get())
      nl.put(evtThrottleCntrKey, throttle == 0 ? EVENTS_LOST_THROTTLE : throttle - 1);

    boolean lost = !lastFound.get() && throttle == 0;

    Collection<VisorGridEvent> res = new ArrayList<>(evts.size() + (lost ? 1 : 0));

    if (lost) res.add(new VisorGridEventsLost(ignite.cluster().localNode().id()));

    for (Event e : evts) {
      VisorGridEvent visorEvt = evtMapper.apply(e);

      if (visorEvt != null) res.add(visorEvt);
    }

    return res;
  }
  /**
   * Sets data configurations.
   *
   * @param dataCfgs Data configurations.
   */
  public void setDataConfigurations(Collection<? extends GridClientDataConfiguration> dataCfgs) {
    this.dataCfgs = U.newHashMap(dataCfgs.size());

    for (GridClientDataConfiguration dataCfg : dataCfgs)
      this.dataCfgs.put(dataCfg.getName(), new GridClientDataConfiguration(dataCfg));
  }