예제 #1
1
파일: Ads.java 프로젝트: habib123/SEBA
  public static void viewAd(String id) {

    Ad ad = Ad.findById(Long.parseLong(id));
    List<Category> cats = Category.find("categorytype_id=?1 order by id", "1").fetch();

    EntityManager entityManager = play.db.jpa.JPA.em();
    List<BigInteger> bCounts =
        entityManager
            .createNativeQuery(
                "select count(*) as maxCount from Ad as a group by category_id order by maxCount")
            .getResultList();
    int min = bCounts.get(0).intValue();
    int max = bCounts.get(bCounts.size() - 1).intValue();
    bCounts =
        entityManager
            .createNativeQuery(
                "select count(*) as maxCount from Ad as a group by category_id order by category_id ")
            .getResultList();
    List<String> fonts = new ArrayList<String>();
    for (int i = 0; i < bCounts.size(); i++) {
      BigInteger count = bCounts.get(i);
      int x = Ads.getFontSize(count.intValue(), min, max);
      fonts.add(String.valueOf(x));
    }

    render(ad, fonts, min, max, cats);
  }
  public void displayConfusionMatrix() {
    int total = 0;
    int wrong = 0;
    System.out.print("  |   ");
    for (Category c : categories.values()) {
      System.out.print(c.getCategory() + "  |   ");
      total += c.totalCategorized;
      wrong += c.wrong;
    }
    System.out.println();

    for (Category c : categories.values()) {
      String out = c.getCategory() + " | ";
      for (String c2 : categories.keySet()) {
        if (c.categorized.containsKey(c2))
          out += String.format("%.2f | ", c.categorized.get(c2) / (c.totalCategorized * 1.0));
        else out += "0000 | ";
      }
      System.out.println(out);
    }

    System.out.println("Accuracy: " + Math.round(100 * (total - wrong * 1.0) / total) + "%");

    System.out.println();
  }
예제 #3
0
 public static Category createCategory(EOEditingContext editingContext, Integer id, String name) {
   Category eo =
       (Category) EOUtilities.createAndInsertInstance(editingContext, _Category.ENTITY_NAME);
   eo.setId(id);
   eo.setName(name);
   return eo;
 }
예제 #4
0
 @Test
 public void findRepostByCategories_Entity_複数_00() {
   Category cat1 = Category.findBySerialCode("cat-biz").first();
   Category cat2 = Category.findBySerialCode("cat-enta").first();
   List<RepostBase> lst = RepostBase.findRepostByCategories(cat1, cat2).fetch();
   assertThat(lst.size(), is(5));
   // DBからの取得リストの並び保証なし
 }
예제 #5
0
파일: Bot.java 프로젝트: dims12/program-ab
 public void deleteLearnCategories() {
   ArrayList<Category> learnCategories = learnGraph.getCategories();
   for (Category c : learnCategories) {
     Nodemapper n = brain.findNode(c);
     System.out.println("Found node " + n + " for " + c.inputThatTopic());
     if (n != null) n.category = null;
   }
   learnGraph = new Graphmaster(this);
 }
예제 #6
0
 @Test
 public void findRepostByCategories_Entity_複数_投稿者_00() {
   Category cat1 = Category.findBySerialCode("cat-biz").first();
   Category cat2 = Category.findBySerialCode("cat-enta").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByCategories(cat1, cat2).contributor(acnt).fetch();
   assertThat(lst.size(), is(3));
   // DBからの取得リストの並び保証なし
 }
예제 #7
0
 @Factory("category9List")
 public void initCategory9List() {
   log.info("initCategory9List");
   category9List = new HashMap<String, String>();
   for (Object o : em.createQuery("from " + "Category").getResultList()) {
     Category p = (Category) o;
     category9List.put(p.getName(), p.getId().toString());
   }
 }
예제 #8
0
  private void displayCategory(Category c, Player p) {
    p.sendMessage("----Available Commands and Sub-Categories----");
    p.sendMessage("-----------------------------------------");
    for (Command com : c.listCommands()) {
      p.sendMessage(com.toString());
    }

    for (Category subCat : c.listCategories()) {
      p.sendMessage(subCat.toString());
    }
  }
  public void printTopTwenties() {
    for (Category c : categories.values()) {
      System.out.println("Class: " + c.getCategory());
      List<String> twenty = c.topTwentyWords();

      for (int i = 0; i < twenty.size(); i++) {
        System.out.println(i + ": " + twenty.get(i));
      }

      System.out.println();
    }
  }
예제 #10
0
  private static void parseNode(Node n, Category parent) {
    String name = n.getNodeName();
    if (name.equals("Category")) {
      Category cat = parseCategory(n);
      parent.addCategory(cat);
    }

    if (name.equals("Command")) {
      Command com = parseCommand(n);
      parent.addCommand(com);
    }
  }
예제 #11
0
 /** Gathers and propagates the unique values of each distributive attribute. */
 public void propagateDistributiveAttrs(Category cat, Category cat2) {
   if (_distributiveAttrs == null) return;
   resetDistrAttrVals();
   cat.forall(gatherDistrAttrVals);
   if (cat2 != null) {
     cat2.forall(gatherDistrAttrVals);
   }
   cat.forall(propagateUniqueDistrAttrVals);
   if (cat2 != null) {
     cat2.forall(propagateUniqueDistrAttrVals);
   }
 }
예제 #12
0
  /**
   * Deletes an existing Category Validation: Check if category exists, Check if validation string
   * equals catgory name
   *
   * @param cat Category Object to be removed
   * @param validation String to validate if the user surely wants to remove the Category
   * @return true if Category Object is removed, returns false if this is not the case.
   */
  public boolean deleteCategory(Category cat, String validation) {

    if (validation.equals(cat.getName())) {

      for (Category c : categoryList) {
        if (c.getName().equals(cat.getName())) {
          categoryList.remove(c);
          return true;
        }
      }
    }
    return false;
  }
  private void createProbabilities() {

    for (Category c : categories.values()) {
      c.setPrior((c.getCount() * 1.0) / totalClassRecords);

      double k = 0.1;
      double v = categories.size() * 1.0;
      for (String word : words) {
        double p = (c.getWordCount(word) + k) / (c.getCount() + k * v);
        c.wordConditionals.put(word, p);
      }
    }
  }
예제 #14
0
 /**
  * Updates or insert a new a category
  *
  * @param category Category to be updated or inserted
  * @return Rows affected or new inserted category id
  */
 public Category updateCategory(Category category) {
   ContentValues values = new ContentValues();
   values.put(
       KEY_CATEGORY_ID,
       category.getId() != null ? category.getId() : Calendar.getInstance().getTimeInMillis());
   values.put(KEY_CATEGORY_NAME, category.getName());
   values.put(KEY_CATEGORY_DESCRIPTION, category.getDescription());
   values.put(KEY_CATEGORY_COLOR, category.getColor());
   getDatabase(true)
       .insertWithOnConflict(
           TABLE_CATEGORY, KEY_CATEGORY_ID, values, SQLiteDatabase.CONFLICT_REPLACE);
   return category;
 }
예제 #15
0
 @Test
 public void findRepostByCategories_Entity_複数_投稿者_降順_00() {
   Category cat1 = Category.findBySerialCode("cat-biz").first();
   Category cat2 = Category.findBySerialCode("cat-enta").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByCategories(cat1, cat2)
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(3));
   assertThat(lst.get(0).getLabel().serialCode, is("cat-biz"));
 }
예제 #16
0
 /** Expands inheritsFrom links to feature equations for those features not explicitly listed. */
 public void expandInheritsFrom(Category cat, Category cat2) {
   // index feature structures
   featStrucMap.clear();
   cat.forall(indexFeatStrucs);
   if (cat2 != null) {
     cat2.forall(indexFeatStrucs);
   }
   // add feature eqs
   cat.forall(doInheritsFrom);
   if (cat2 != null) {
     cat2.forall(doInheritsFrom);
   }
 }
예제 #17
0
파일: Bot.java 프로젝트: dims12/program-ab
  /** Write all AIML files. Adds categories for BUILD and DEVELOPMENT ENVIRONMENT */
  public void writeAIMLFiles() {
    if (MagicBooleans.trace_mode) System.out.println("writeAIMLFiles");
    HashMap<String, BufferedWriter> fileMap = new HashMap<String, BufferedWriter>();
    Category b = new Category(0, "BRAIN BUILD", "*", "*", new Date().toString(), "update.aiml");
    brain.addCategory(b);
    // b = new Category(0, "PROGRAM VERSION", "*", "*", MagicStrings.program_name_version,
    // "update.aiml");
    // brain.addCategory(b);
    ArrayList<Category> brainCategories = brain.getCategories();
    Collections.sort(brainCategories, Category.CATEGORY_NUMBER_COMPARATOR);
    for (Category c : brainCategories) {

      if (!c.getFilename().equals(MagicStrings.null_aiml_file))
        try {
          // System.out.println("Writing "+c.getCategoryNumber()+" "+c.inputThatTopic());
          BufferedWriter bw;
          String fileName = c.getFilename();
          if (fileMap.containsKey(fileName)) bw = fileMap.get(fileName);
          else {
            String copyright = Utilities.getCopyright(this, fileName);
            bw = new BufferedWriter(new FileWriter(aiml_path + "/" + fileName));
            fileMap.put(fileName, bw);
            bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" + "<aiml>\n");
            bw.write(copyright);
            // bw.newLine();
          }
          bw.write(Category.categoryToAIML(c) + "\n");
          // bw.newLine();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
    }
    Set set = fileMap.keySet();
    for (Object aSet : set) {
      BufferedWriter bw = fileMap.get(aSet);
      // Close the bw
      try {
        if (bw != null) {
          bw.write("</aiml>\n");
          bw.flush();
          bw.close();
        }
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    File dir = new File(aiml_path);
    dir.setLastModified(new Date().getTime());
  }
예제 #18
0
  @Override
  public boolean equals(Object obj) {

    if (this == obj) return true;
    if (obj.hashCode() == 0) return false;
    if (obj == null) return false;
    Category other = (Category) obj;

    //    System.out.println("comparing selected category: " + other.getName() );
    if (name == null) {
      if (other.getName() != null) return false;
    } else if (!name.equals(other.getName())) return false;

    return true;
  }
예제 #19
0
파일: Bot.java 프로젝트: dims12/program-ab
 /**
  * read AIMLIF categories from a file into bot brain
  *
  * @param filename name of AIMLIF file
  * @return array list of categories read
  */
 public ArrayList<Category> readIFCategories(String filename) {
   ArrayList<Category> categories = new ArrayList<Category>();
   try {
     // Open the file that is the first
     // command line parameter
     FileInputStream fstream = new FileInputStream(filename);
     // Get the object
     BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
     String strLine;
     // Read File Line By Line
     while ((strLine = br.readLine()) != null) {
       try {
         Category c = Category.IFToCategory(strLine);
         categories.add(c);
       } catch (Exception ex) {
         System.out.println("Invalid AIMLIF in " + filename + " line " + strLine);
       }
     }
     // Close the input stream
     br.close();
   } catch (Exception e) { // Catch exception if any
     System.err.println("Error: " + e.getMessage());
   }
   return categories;
 }
예제 #20
0
 public static String getCategoryPath(Category category) {
   String path = "";
   int level = category.getPathInTree().size();
   if (level > 1) {
     // Add first 2 oldest ancestors separated by '-'
     List<Category> ancestors = category.getPathInTree().subList(0, level - 1);
     String ancestorsPath = ancestors.get(0).getSlug();
     if (ancestors.size() > 1) {
       ancestorsPath += "-" + ancestors.get(1).getSlug();
     }
     path += ancestorsPath + "/";
   }
   // Add current category
   path += category.getPathInTree().get(level - 1).getSlug();
   return path;
 }
예제 #21
0
파일: Bot.java 프로젝트: dims12/program-ab
 /**
  * write categories to AIMLIF file
  *
  * @param cats array list of categories
  * @param filename AIMLIF filename
  */
 public void writeIFCategories(ArrayList<Category> cats, String filename) {
   // System.out.println("writeIFCategories "+filename);
   BufferedWriter bw = null;
   File existsPath = new File(aimlif_path);
   if (existsPath.exists())
     try {
       // Construct the bw object
       bw = new BufferedWriter(new FileWriter(aimlif_path + "/" + filename));
       for (Category category : cats) {
         bw.write(Category.categoryToIF(category));
         bw.newLine();
       }
     } catch (FileNotFoundException ex) {
       ex.printStackTrace();
     } catch (IOException ex) {
       ex.printStackTrace();
     } finally {
       // Close the bw
       try {
         if (bw != null) {
           bw.flush();
           bw.close();
         }
       } catch (IOException ex) {
         ex.printStackTrace();
       }
     }
 }
예제 #22
0
 /**
  * Compares the categories and returns the 'active' class if are the same.
  *
  * @param category
  * @param currentCategory
  * @return 'active' if categories are the same, otherwise an empty string.
  */
 public static String getActiveClass(Category category, Category currentCategory) {
   String active = "";
   if (currentCategory != null && currentCategory.getPathInTree().contains(category)) {
     active = "active";
   }
   return active;
 }
예제 #23
0
  protected ConfigElement processTextLine(String configfile, int lineno, String line)
      throws ConfigParseException {
    ConfigElement configElement;

    if (line.charAt(0) == '[') // A category header
    {
      configElement = parseCategoryHeader(configfile, lineno, line);
    } else if (line.charAt(0) == '#') // a directive - #include or #exec
    {
      configElement = parseDirective(configfile, lineno, line);
    } else // just a line
    {
      if (currentCategory == null) {
        throw new ConfigParseException(
            configfile,
            lineno,
            "parse error: No category context for line %d of %s",
            lineno,
            configfile);
      }

      configElement = parseVariable(configfile, lineno, line);
      currentCategory.addElement(configElement);
    }

    return configElement;
  }
예제 #24
0
public class Log4JTest {
  // Create a category instance for this class
  static Category cat = Category.getInstance(Log4JTest.class.getName());

  public static void main(String[] args) {
    // Ensure to have all necessary drivers installed !
    try {
      Driver d = (Driver) (Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
      DriverManager.registerDriver(d);
    } catch (Exception e) {
    }

    // Set the priority which messages have to be logged
    cat.setPriority(Priority.INFO);

    // Configuration with configuration-file
    PropertyConfigurator.configure("log4jtestprops.txt");

    // These messages with Priority >= setted priority will be logged to the database.
    cat.debug("debug"); // this not, because Priority DEBUG is less than INFO
    cat.info("info");
    cat.error("error");
    cat.fatal("fatal");
  }
}
예제 #25
0
  public int getCategorizedCount(Category category) {
    int count = 0;
    String sql =
        "SELECT COUNT(*)"
            + " FROM "
            + TABLE_NOTES
            + " WHERE "
            + KEY_CATEGORY
            + " = "
            + category.getId();

    Cursor cursor = null;
    try {
      cursor = getDatabase().rawQuery(sql, null);

      // Looping through all rows and adding to list
      if (cursor.moveToFirst()) {
        count = cursor.getInt(0);
      }

    } finally {
      if (cursor != null) cursor.close();
    }
    return count;
  }
예제 #26
0
 // unify sem class with default nom var(s)
 private void unifySemClass(Category cat, String semClass) {
   if (semClass == null || cat.getLF() == null) return;
   SEMCLASS = grammar.types.getSimpleType(semClass);
   try {
     cat.getLF().deepMap(defaultNomvarUnifier);
   } catch (TypePropagationException tpe) {
     if (debugSemClasses) {
       System.err.println(
           "Warning: unable to unify types '"
               + tpe.st1
               + "' and '"
               + tpe.st2
               + "' in unifying sem class in cat: \n"
               + cat);
     }
   }
 }
예제 #27
0
 public int hashCode() {
   int code = 17;
   code += object.hashCode();
   code *= 37;
   code += category.hashCode();
   code *= 37;
   return code;
 }
  public void testModel(String testFile) {
    Scanner in = null;
    try {
      in = new Scanner(new File(testFile));
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      System.exit(-1);
    }

    String[] line = null;
    while (in.hasNextLine()) {
      line = in.nextLine().split(" ");
      Category trueCat = categories.get(line[0]);
      double max = -Double.MAX_VALUE;
      Category maxCat = null;

      Set<String> docWords = new HashSet<>();

      for (int i = 1; i < line.length; i++) {
        String[] word = line[i].split(":");
        docWords.add(word[0]);
      }

      for (Category c : categories.values()) {
        double value = Math.log(c.getPrior());
        for (String word : words) {
          double p = c.wordConditionals.get(word);
          if (docWords.contains(word)) {
            value += Math.log(p);
          } else {
            value += Math.log(1 - p);
          }
        }

        if (max < value) {
          max = value;
          maxCat = c;
        }
      }

      if (maxCat != null) trueCat.addCategorized(maxCat);
    }
  }
예제 #29
0
 /** Propagates types of nomvars in the given categories. */
 public void propagateTypes(Category cat, Category cat2) {
   try {
     nomvarMap.clear();
     cat.deepMap(nomvarTypePropagater);
     if (cat2 != null) cat2.deepMap(nomvarTypePropagater);
     cat.deepMap(nomvarTypePropagater);
     if (cat2 != null) cat2.deepMap(nomvarTypePropagater);
   } catch (TypePropagationException tpe) {
     if (debugSemClasses) {
       System.err.println(
           "Warning: unable to unify types '"
               + tpe.st1
               + "' and '"
               + tpe.st2
               + "' in cat: \n"
               + cat);
       if (cat2 != null) System.err.println("and cat: \n" + cat2);
     }
   }
 }
예제 #30
0
파일: Bot.java 프로젝트: dims12/program-ab
 /** Write all AIMLIF files from bot brain */
 public void writeAIMLIFFiles() {
   if (MagicBooleans.trace_mode) System.out.println("writeAIMLIFFiles");
   HashMap<String, BufferedWriter> fileMap = new HashMap<String, BufferedWriter>();
   Category b = new Category(0, "BRAIN BUILD", "*", "*", new Date().toString(), "update.aiml");
   brain.addCategory(b);
   ArrayList<Category> brainCategories = brain.getCategories();
   Collections.sort(brainCategories, Category.CATEGORY_NUMBER_COMPARATOR);
   for (Category c : brainCategories) {
     try {
       BufferedWriter bw;
       File aimlifFile;
       String fileName = c.getFilename();
       if (fileMap.containsKey(fileName)) bw = fileMap.get(fileName);
       else {
         aimlifFile = new File(aimlif_path + "/" + fileName + MagicStrings.aimlif_file_suffix);
         aimlifFile.getParentFile().mkdirs();
         bw = new BufferedWriter(new FileWriter(aimlifFile));
         fileMap.put(fileName, bw);
       }
       bw.write(Category.categoryToIF(c));
       bw.newLine();
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
   Set set = fileMap.keySet();
   for (Object aSet : set) {
     BufferedWriter bw = fileMap.get(aSet);
     // Close the bw
     try {
       if (bw != null) {
         bw.flush();
         bw.close();
       }
     } catch (IOException ex) {
       ex.printStackTrace();
     }
   }
   File dir = new File(aimlif_path);
   dir.setLastModified(new Date().getTime());
 }