提取关键词

@param document 关键词
@param size     需要几个关键词
@return
552533
public List<String> getKeywords(String document, int size)
    {
        return getKeywords(defaultSegment.seg(document), size);
    }
318109
protected static Document createDocument(String document) throws PolicyIndexException {

        // parse policy document and create dom
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder;
        try {
            builder = factory.newDocumentBuilder();
            Document doc = builder.parse(new InputSource(new StringReader(document)));
            return doc;
        } catch (ParserConfigurationException e) {
            throw new PolicyIndexException(e);
        } catch (SAXException e) {
            throw new PolicyIndexException(e);
        } catch (IOException e) {
            throw new PolicyIndexException(e);
        }
    }
363893
private ContentStream jcrBinaryContent( Document document ) {
        // pickup node properties
        Document props = document.getDocument("properties").getDocument(JcrLexicon.Namespace.URI);

        // extract binary value and content
        Binary value = props.getBinary("data");

        if (value == null) {
            return null;
        }

        byte[] content = value.getBytes();
        String fileName = props.getString("fileName");
        String mimeType = props.getString("mimeType");

        // wrap with input stream
        ByteArrayInputStream bin = new ByteArrayInputStream(content);
        bin.reset();

        // create content stream
        return new ContentStreamImpl(fileName, BigInteger.valueOf(content.length), mimeType, bin);
    }
640229
private static String getText(Document document)
	{
		try
		{
			return document.getText(0, document.getLength());
		}
		catch (BadLocationException exception)
		{
			return null;
		}
	}
539139
private static List<String> getElementsId(Document document) {
        List<String> result = new ArrayList<String>();

        List<Element> elementList = getElements(document);

        result = getElementsId(elementList);

        return result;
    }
947874
@Override
    public void checkDocument(Document document) {
        document.getDefinitions().forEach(definition -> {
            if (!(definition instanceof OperationDefinition)
                && !(definition instanceof FragmentDefinition)) {

                String message = nonExecutableDefinitionMessage(definition);
                addError(ValidationErrorType.NonExecutableDefinition, definition.getSourceLocation(), message);
            }
        });
    }
1102630
function(_document){
                var _selection = _h.__getSelection(_h.__getWindow(_document));
                return _selection.rangeCount ? _selection.getRangeAt(0) : null;
            }
1089032
private void compact(Document doc, QueryAdapter queryAdapter) {
		if (queryAdapter != null && queryAdapter.getCompactMode()) {
			if (doc.getIncluded() != null) {
				compact(doc.getIncluded());
			}
			if (doc.getData().isPresent()) {
				if (doc.isMultiple()) {
					compact(doc.getCollectionData().get());
				} else {
					compact(doc.getSingleData().get());
				}
			}
		}
	}
45645
public static List<String> getKeywordList(String document, int size)
    {
        return new TermFrequencyCounter().getKeywords(document, size);
    }
1168977
private static org.w3c.dom.Document toDom(final Document doc) {
        try {
            val xmlOutputter = new XMLOutputter();
            val elemStrWriter = new StringWriter();
            xmlOutputter.output(doc, elemStrWriter);
            val xmlBytes = elemStrWriter.toString().getBytes(Charset.defaultCharset());
            val dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
            dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            dbf.setFeature("http://apache.org/xml/features/validation/schema/normalized-value", false);
            dbf.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
            dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
            dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);

            return dbf.newDocumentBuilder().parse(new ByteArrayInputStream(xmlBytes));
        } catch (final Exception e) {
            LOGGER.trace(e.getMessage(), e);
            return null;
        }
    }
284802
function(size) {
		if (typeof(size) !== 'string') {
			return size;
		}
		
		var muls = {
				t: 1099511627776,
				g: 1073741824,
				m: 1048576,
				k: 1024
			},
			mul;

		size = /^([0-9]+)([mgk]?)$/.exec(size.toLowerCase().replace(/[^0-9mkg]/g, ''));
		mul = size[2];
		size = +size[1];
		
		if (muls.hasOwnProperty(mul)) {
			size *= muls[mul];
		}
		return size;
	}
503596
public int addDocument(String document) {
    if (root().getNumberOfChildren() >= 0) {
      throw new IllegalStateException("Tree sorting has begun");
    }
    final int index;
    synchronized (this) {
      index = documents.size();
      documents.add(document);
    }
    cursors.addAll(
      IntStream.range(0, document.length() + 1).mapToObj(i -> new CursorData(index, i)).collect(Collectors.toList()));
    nodes.update(0, node -> node.setCursorCount(cursors.length()));
    return index;
  }
249871
public static String documentToPrettyString(Document document) {
        StringWriter stringWriter = new StringWriter();
        OutputFormat prettyPrintFormat = OutputFormat.createPrettyPrint();
        XMLWriter xmlWriter = new XMLWriter(stringWriter, prettyPrintFormat);

        try {
            xmlWriter.write(document);
        } catch (IOException e) {
            // Ignore, shouldn't happen.
        }

        return stringWriter.toString();
    }
1333524
public static DocumentAndSize [] cut(final Document doc,final PageSize size) {
		NodeList nl = doc.getElementsByTagNameNS("http://www.allcolor.org/xmlns/yahp",
				"pb");
		
		if (nl.getLength() == 0) {
			// see if someone forget namespace decl ?
			nl = doc.getElementsByTagName("yahp:pb");
		}

		// if no pagebreak found, return the given document.
		if (nl.getLength() == 0) {
			return new DocumentAndSize [] { new DocumentAndSize(doc,size) };
		} // end if

		// get the start-end offset of all page breaks.
		PbDocument pbdocs[] = getPbDocs(nl);

		// create as much document as they are pages.
		DocumentAndSize array[] = new DocumentAndSize[pbdocs.length];
		for (int i = 0; i < pbdocs.length; i++) {
			PbDocument pbdoc = pbdocs[i];

			// get start and end offset
			Element pbstart = (Element) pbdoc.getPbStart();
			Element pbend = (Element) pbdoc.getPbEnd();
			
			PageSize tmpSize = getPageSize(pbstart == null ? null : pbstart.getAttribute("size"),size);

			// create a new doc and set the URI
			ADocument ndoc = new CDom2HTMLDocument();
			ndoc.setDocumentURI(doc.getDocumentURI());

			CNamespace xmlnsdef = new CNamespace((pbend != null)
					? pbend.getPrefix()
					: pbstart.getPrefix(),
					"http://www.allcolor.org/xmlns/yahp");
			ndoc.getNamespaceList().add(xmlnsdef);

			if (pbend == null) {
				// from pbstart to the end of the document.
				// create the container node
				Element parentPb = (Element) ndoc.adoptNode(pbstart.getParentNode()
																	   .cloneNode(false));

				// copy all next siblings
				Node Sibling = pbstart.getNextSibling();

				while (Sibling != null) {
					Node node = ndoc.adoptNode(Sibling.cloneNode(true));
					// add to container node
					parentPb.appendChild(node);
					Sibling = Sibling.getNextSibling();
				} // end while

				// copy parent node of the start page break
				Node parent   = pbstart.getParentNode();
				Node nextNode = null;
				Node ppr	  = null;

				while (parent != null) {
					if (parent.getNodeType() == Node.ELEMENT_NODE) {
						// copy the node
						Node node = ndoc.adoptNode(parent.cloneNode(
									false));

						if (nextNode != null) {
							// append the node to the container
							node.appendChild(nextNode);

							if (!("body".equals(ppr.getNodeName()))) {
								// append next sibling of the previous container
								Sibling = ppr.getNextSibling();

								while (Sibling != null) {
									Node n = ndoc.adoptNode(Sibling.cloneNode(
												true));
									node.appendChild(n);
									Sibling = Sibling.getNextSibling();
								} // end while
							} // end if

							nextNode = node;
						} // end if
						else {
							nextNode = parentPb;
						} // end else

						ppr = parent;
					} // end if

					parent = parent.getParentNode();
				} // end while

				ndoc.appendChild(nextNode);
			} // end if
			else {
				Element parentPb   = (Element) ndoc.adoptNode(pbend.getParentNode()
																	   .cloneNode(false));
				Node    Sibling    = pbend.getPreviousSibling();
				boolean hasbeendes = false;

				while (!hasbeendes && (Sibling != null)) {
					if (isDescendant(pbstart, Sibling)) {
						hasbeendes = true;

						break;
					} // end if

					Node node = ndoc.adoptNode(Sibling.cloneNode(true));

					if (parentPb.getChildNodes().getLength() == 0) {
						parentPb.appendChild(node);
					} // end if
					else {
						parentPb.insertBefore(node,
							parentPb.getFirstChild());
					} // end else

					Sibling = Sibling.getPreviousSibling();
				} // end while
				
				if (hasbeendes && pbstart != Sibling) {
					Node c  = ndoc.adoptNode(Sibling.cloneNode(
								true));
					((Element)c).setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:yahp", "http://www.allcolor.org/xmlns/yahp");
					Node pb = ((Element) c).getElementsByTagNameNS("http://www.allcolor.org/xmlns/yahp",
							"pb").item(0);
					Node p  = pb;
					Node pp = pb.getParentNode()
									.getPreviousSibling();

					while (p != null) {
						Node tmp = p.getPreviousSibling();
						p.getParentNode()
							 .removeChild(p);
						p = tmp;
					} // end while

					while (pp != null) {
						Node tmp = pp.getPreviousSibling();

						if (tmp == null) {
							Node ppz = pp.getParentNode();

							if (ppz.getPreviousSibling() != null) {
								tmp = ppz.getPreviousSibling();
							} // end if
							else {
								Node prev = null;

								while (prev == null) {
									ppz = ppz.getParentNode();

									if (ppz == null) {
										break;
									} // end if

									prev = ppz.getPreviousSibling();
								} // end while

								if (prev != null) {
									tmp = prev;
								} // end if
							} // end else
						} // end if

						pp.getParentNode()
							  .removeChild(pp);
						pp = tmp;
					} // end while

					if (parentPb.getChildNodes()
								.getLength() == 0) {
						parentPb.appendChild(c);
					} // end if
					else {
						parentPb.insertBefore(c,
								parentPb.getFirstChild());
					} // end else
				} // end if				
				

				Node parent		  = pbend.getParentNode();
				Node previousNode = null;
				Node ppr		  = null;

				while (parent != null) {
					if (parent.getNodeType() == Node.ELEMENT_NODE) {
						if (previousNode != null) {
							Node node = ndoc.adoptNode(parent.cloneNode(
									false));
							node.appendChild(previousNode);

							if (!("body".equals(ppr.getNodeName()))) {
								Sibling = ppr.getPreviousSibling();

								while (!hasbeendes &&
										(Sibling != null)) {
									if (isDescendant(pbstart, Sibling)) {
										// here special handling need to be
										// taken.
										if (pbstart != Sibling) {
											Node c  = ndoc.adoptNode(Sibling.cloneNode(
														true));
											Node pb = ((Element) c).getElementsByTagNameNS("http://www.allcolor.org/xmlns/yahp",
													"pb").item(0);
											Node p  = pb;
											Node pp = pb.getParentNode()
															.getPreviousSibling();

											while (p != null) {
												Node tmp = p.getPreviousSibling();
												p.getParentNode()
													 .removeChild(p);
												p = tmp;
											} // end while

											while (pp != null) {
												Node tmp = pp.getPreviousSibling();

												if (tmp == null) {
													Node ppz = pp.getParentNode();

													if (ppz.getPreviousSibling() != null) {
														tmp = ppz.getPreviousSibling();
													} // end if
													else {
														Node prev = null;

														while (prev == null) {
															ppz = ppz.getParentNode();

															if (ppz == null) {
																break;
															} // end if

															prev = ppz.getPreviousSibling();
														} // end while

														if (prev != null) {
															tmp = prev;
														} // end if
													} // end else
												} // end if

												pp.getParentNode()
													  .removeChild(pp);
												pp = tmp;
											} // end while

											if (node.getChildNodes()
														.getLength() == 0) {
												node.appendChild(c);
											} // end if
											else {
												node.insertBefore(c,
													node.getFirstChild());
											} // end else
										} // end if

										hasbeendes = true;

										break;
									} // end if

									Node n = ndoc.adoptNode(Sibling.cloneNode(
												true));

									if (node.getChildNodes().getLength() == 0) {
										node.appendChild(n);
									} // end if
									else {
										node.insertBefore(n,
											node.getFirstChild());
									} // end else

									Sibling = Sibling.getPreviousSibling();
								} // end while
							} // end if

							previousNode = node;
						} // end if
						else {
							previousNode = parentPb;
						} // end else

						ppr = parent;
					} // end if

					parent = parent.getParentNode();
				} // end while

				ndoc.appendChild(previousNode);
			} // end else

			// copy header
			copyHeader(doc, ndoc);
			array[i] = new DocumentAndSize(ndoc,tmpSize);
		} // end for

		return array;
	}
1337791
@SuppressWarnings("unchecked")
    public static org.bson.Document decodeMongoDoc(org.bson.Document doc) {
        org.bson.Document newDoc = new org.bson.Document();
        for (String key : doc.keySet()) {
            Object value = doc.get(key);
            if (value instanceof org.bson.Document)
                value = decodeMongoDoc(doc.get(key, org.bson.Document.class));
            else if (value instanceof List<?>) {
                for (int i=0; i < ((List<?>)value).size(); i++) {
                    Object obj = ((List<?>)value).get(i);
                    if (obj instanceof org.bson.Document)
                        ((List<org.bson.Document>)value).set(i, decodeMongoDoc((org.bson.Document)obj));
                }
            }

            String newKey = key;
            if (key.startsWith("\\uff04"))
                newKey = "$" + key.substring(6);
            if (key.contains("\\uff0e")) {
                newKey = newKey.replace("\\uff0e", ".");
            }
            newDoc.put(newKey, value);
        }
        return newDoc;
    }
891136
public void add(DOCUMENT doc) {
      if (doc != null) {
         documents.add(doc);
         int id = documents.size() - 1;
         for (KEY key : documentMapper.apply(doc)) {
            index.put(key, id);
         }
      }
   }
1356519
@View(name = "size", map = "function(doc) { if (doc.service) { emit(doc, doc._id) }}", reduce = "_count")
    public int size() {
        val r = db.queryView(createQuery("size"));
        LOGGER.trace("r.isEmpty [{}]", r.isEmpty());
        LOGGER.trace("r.getRows [{}]", r.getRows());
        if (r.isEmpty()) {
            return 0;
        }

        return r.getRows().get(0).getValueAsInt();
    }