当前位置: 首页>>代码示例>>Java>>正文


Java CRFClassifier.getClassifier方法代码示例

本文整理汇总了Java中edu.stanford.nlp.ie.crf.CRFClassifier.getClassifier方法的典型用法代码示例。如果您正苦于以下问题:Java CRFClassifier.getClassifier方法的具体用法?Java CRFClassifier.getClassifier怎么用?Java CRFClassifier.getClassifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.stanford.nlp.ie.crf.CRFClassifier的用法示例。


在下文中一共展示了CRFClassifier.getClassifier方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ner

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
public List<IntPair> ner(String s) {
    try {
        if (classifier == null) {
            classifier = CRFClassifier.getClassifier(classifierFile);
        }
        List<List<CoreLabel>> result = classifier.classify(s);
        int begin = 0;
        String last = "";
        boolean in = false;
        int j = 0;
        List<IntPair> rval = new ArrayList<>();
        for (CoreLabel word : result.get(0)) {
            String tag = word.get(CoreAnnotations.AnswerAnnotation.class);
            if (tag.equals("O")) {
                if (in) {
                    rval.add(new IntPair(begin, j));
                }
                in = false;
            } else {
                if (!in) {
                    begin = j;
                    in = true;
                }
            }
            j++;
            last = tag;
        }
        if (in) {
            rval.add(new IntPair(begin, result.get(0).size()));
        }
        return rval;
    } catch (IOException | ClassNotFoundException x) {
        throw new RuntimeException(x);
    }
}
 
开发者ID:jmccrae,项目名称:naisc,代码行数:36,代码来源:SultanModified.java

示例2: init

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
@Override
public Resource init() throws ResourceInstantiationException {
  if(tagger == null) {
    fireStatusChanged("Loading Stanford NER model");
    try (InputStream in = modelFile.openStream();
        GZIPInputStream gzipIn = new GZIPInputStream(in)){
      tagger = CRFClassifier.getClassifier(gzipIn);
    } catch(Exception e) {
      throw new ResourceInstantiationException(e);
    }
  }
  return this;
}
 
开发者ID:GateNLP,项目名称:gateplugin-Stanford_CoreNLP,代码行数:14,代码来源:NER.java

示例3: initialValue

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
protected AbstractSequenceClassifier<CoreLabel> initialValue() {
	try {
		return CRFClassifier.getClassifier(classifierFilePath);
	} catch (final Exception exception) {
		LOGGER.error(MessageCatalog._00052_CLASSIFIER_LOAD_FAILURE, classifierFilePath);
		return NULL_OBJECT_CLASSIFIER;
	}
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:9,代码来源:NERThreadLocalService.java

示例4: classifier

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
@Override
AbstractSequenceClassifier<CoreLabel> classifier() {
	synchronized(this) {
		if (classifier == null) {
				try {
					classifier = CRFClassifier.getClassifier(classifierFilePath);
				} catch (final Exception exception) {
					LOGGER.error(MessageCatalog._00052_CLASSIFIER_LOAD_FAILURE, classifierFilePath);
					classifier = NULL_OBJECT_CLASSIFIER;
				}
		}
		return classifier;
	}
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:15,代码来源:NERSingletonService.java

示例5: init

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
public void init() throws NamedEntityRecognizerException
{
	if (initialized)
		throw new NamedEntityRecognizerException(
				"init() was called though the StanfordNamedEntityRecognizer was already initialized.");
	try
	{
		this.crfClassifier = CRFClassifier.getClassifier(this.classifierPath.getPath());
		this.initialized = true;
	}
	catch (Exception e)
	{
		throw new NamedEntityRecognizerException("Classifier load failed.",e);
	}
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:16,代码来源:StanfordNamedEntityRecognizer.java

示例6: NER

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
public NER() {
    try {
        classifier = CRFClassifier.<CoreLabel> getClassifier(new File(SERIALIZED_CLASSIFIER));
    } catch (ClassCastException | ClassNotFoundException | IOException e) {
        Throwables.propagate(e);
    }
}
 
开发者ID:CodeforLeipzig,项目名称:lvz-viz,代码行数:8,代码来源:NER.java

示例7: setup

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void setup(Context context) throws IOException, InterruptedException {
	super.setup(context);
	numrecords = 0;
	try {
		classifier = ((AbstractSequenceClassifier<CoreLabel>) CRFClassifier.getClassifier(NERMapper.class.getResourceAsStream("/nl/surfsara/warcexamples/hadoop/wet/resources/english.all.3class.distsim.crf.ser")));
	} catch (Exception e) {
		logger.error(e);
	}
}
 
开发者ID:norvigaward,项目名称:warcexamples,代码行数:12,代码来源:NERMapper.java

示例8: init

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
/**
 * Initializes the StanfordNeTagger with a custom model.
 * 
 * @param customSerializedClassifier path of the custom classifier to load
 */
public static boolean init(String customSerializedClassifier) {
	try {
		classifier =
			CRFClassifier.getClassifier(customSerializedClassifier);
		serializedClassifier = customSerializedClassifier;
		return true;
	} catch (Exception e) {
		return false;
	}
}
 
开发者ID:claritylab,项目名称:lucida,代码行数:16,代码来源:StanfordNeTagger.java

示例9: init

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
@Override
public Resource init() throws ResourceInstantiationException {
  if(tagger == null) {
    fireStatusChanged("Loading Stanford NER model");
    try {
      // nasty workaround for stanford NER's path format inconsistency - tagger is content with uris beginning file:, ner labeller is not
      tagger = CRFClassifier.getClassifier(modelFile.toString().substring(5));
    } catch(Exception e) {
      throw new ResourceInstantiationException(e);
    }
  }
  return this;
}
 
开发者ID:vita-us,项目名称:ViTA,代码行数:14,代码来源:NER.java

示例10: createClassifier

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
private AbstractSequenceClassifier<CoreLabel> createClassifier() throws ClassCastException, ClassNotFoundException, IOException {
	String classifierPath = classifierFile.getAbsolutePath();
	return CRFClassifier.getClassifier(classifierPath);
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:5,代码来源:StanfordNER.java

示例11: getCharacters

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
/**
 * Get the characters.
 *
 * @return an ArrayList of characters
 */
public ArrayList<Person> getCharacters() {
    ArrayList<Person> people = new ArrayList<Person>();
    Genderize api = GenderizeIoAPI.create();

    AbstractSequenceClassifier<CoreLabel> classifier;
    String fileContents;
    List<Triple<String, Integer, Integer>> list;
    HashSet<String> existingNames;

    try {
        classifier = CRFClassifier.getClassifier(CLASSIFIER);
        fileContents = IOUtils.slurpFile(filename);
        list = classifier.classifyToCharacterOffsets(fileContents);

        existingNames = new HashSet<String>();
        for (Triple<String, Integer, Integer> item : list) {
            if (item.first().equals("PERSON")) {
                String nameStr = fileContents.substring(item.second(),
                                                        item.third());
                nameStr = nameStr.replace("\n", " ")
                    .replace("\r", " ")
                    .replaceAll("\\s+", " ")
                    .trim();

                if (!existingNames.contains(nameStr)) {
                    existingNames.add(nameStr);

                    String[] names = nameStr.split(" ");
                    Person p = new Person();
                    p.setFirstname(names[0]);
                    if (names.length > 1) {
                        p.setLastname(names[1]);
                    }

                    NameGender gender = api.getGender(p.getFirstname());
                    if (gender.getGender() != null) {
                        p.setGender(gender.isMale() ? male : female);
                    } else {
                        p.setGender(getRandomGender());
                    }

                    people.add(p);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return people;
}
 
开发者ID:kennanmeyer,项目名称:SE-410-Project,代码行数:57,代码来源:PersonImporter.java

示例12: main

import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
/**
 * Starts this server on the specified port.  The classifier used can be
 * either a default one stored in the jar file from which this code is
 * invoked or you can specify it as a filename or as another classifier
 * resource name, which must correspond to the name of a resource in the
 * /classifiers/ directory of the jar file.
 * <p>
 * Usage: <code>java edu.stanford.nlp.ie.NERServer [-loadClassifier file|-loadJarClassifier resource|-client] -port portNumber</code>
 *
 * @param args Command-line arguments (described above)
 * @throws Exception If file or Java class problems with serialized classifier
 */
@SuppressWarnings({"StringEqualsEmptyString"})
public static void main (String[] args) throws Exception {
  Properties props = StringUtils.argsToProperties(args);
  String loadFile = props.getProperty("loadClassifier");
  String loadJarFile = props.getProperty("loadJarClassifier");
  String client = props.getProperty("client");
  String portStr = props.getProperty("port");
  props.remove("port"); // so later code doesn't complain
  if (portStr == null || portStr.equals("")) {
    System.err.println(USAGE);
    return;
  }
  String charset = "utf-8";
  String encoding = props.getProperty("encoding");
  if (encoding != null && ! "".equals(encoding)) {
    charset = encoding;
  }
  int port;
  try {
    port = Integer.parseInt(portStr);
  } catch (NumberFormatException e) {
    System.err.println("Non-numerical port");
    System.err.println(USAGE);
    return;
  }
  // default output format for if no output format is specified
  if (props.getProperty("outputFormat") == null) {
    props.setProperty("outputFormat", "slashTags");
  }

  if (client != null && ! client.equals("")) {
    // run a test client for illustration/testing
    String host = props.getProperty("host");
    NERClient.communicateWithNERServer(host, port, charset);
  } else {
    AbstractSequenceClassifier asc;
    if (loadFile != null && ! loadFile.equals("")) {
      asc = CRFClassifier.getClassifier(loadFile, props);
    } else if (loadJarFile != null && ! loadJarFile.equals("")) {
      asc = CRFClassifier.getJarClassifier(loadJarFile, props);
    } else {
      asc = CRFClassifier.getDefaultClassifier(props);
    }

    new NERServer(port, asc, charset).run();
  }
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:60,代码来源:NERServer.java


注:本文中的edu.stanford.nlp.ie.crf.CRFClassifier.getClassifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。