문제

I have data in following format

<foo bar> <property abc> <this foo bar> .

Now there are essentially 4 parts in this string: foo bar; property abc; this foo bar; and .. How do I tokenize the above string into these four parts?

도움이 되었습니까?

해결책 2

String[] array = string.split("> ");

for (int i = 0; i < array.length -1; i++){
    System.out.println(array[i] + ">");
}
System.out.println(array[array.length-1]);

다른 팁

As others have suggested if you want to parse RDF graphs just use a library like Apache Jena (disclaimer - I am one of the developers).

If your problem is more that you need direct control over the parsing process then there are several options:

  • Jena has a TokenizerText class which can tokenize NTriple/Turtle/SPARQL like data if you want to work with the data at the textual level
  • You can implement StreamRDF interface and use this with the built-in parsers to control what happens to the data as it is parsed at the triple/quad level
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top