# How to create a system to detect text structure of a file?

Let's say I want to create a Machine Learning system that has a lot of log files of some few types (F1, F2,.. Fn) and I get a new Log file with maybe some errors or missing data.

How do I classify it into these class types or classify it is an anomaly if it doesn't belong to anyone of them.

I thought about anomaly detection but couldn't figure how to parse structure information from the text classes like (F1, F2... .etc).

Also what kind of structural information to extract from text files?

These input classes contain 100 - 1000 lines of code per document of each class type.

I looked into Linting or DeepCode ...

A sample log file looks like this:

11-02-11 16:47:35,985 +0000 E Activity class {com.trackingeng/LandingActivity} does not exist.
12-02-11 17:47:35,985 +0000 I Starting: Intent { act=android.intent.action.MAIN
.....


A log file may have stack trace like this also:

Error:
Error detail 1
Error detail 2
....
Non-Error:
.....
Warning:
.....
and similar to this.


Any help in which direction to look for is greatly appreciated.

• Please can you edit your post to provide an example of the input log files and their types. How many types in total do you expect to receive, or is it unbounded? – BenP May 24 '19 at 7:29
• Just updated @BenP – Kartikey Singh May 24 '19 at 7:41
• Thanks. Still hard to gauge without an example of log data from two or more separate classes. Is the content of each log of class n likely to be different? My initial thought is that you could build a 1-v-rest (or similar) multi-label classifier to determine the type of log based on typical content. – BenP May 24 '19 at 8:17
• The data for each class is of similar manner but errors produced maybe from android, desktop .etc and the structure of errors i.e. tab spacing differentiates them.So, how to extract structural information from text to apply ML to it? – Kartikey Singh May 24 '19 at 9:00
• So could you engineer features with regex to capture the: i) source OS, and ii) tabbed structural information in the error lines? For example the number of tabs, sequences of tabs, and use these to train a model? – BenP May 24 '19 at 9:20

1. You have an ML that is doing work across multiple systems and users. Generating logs.
2. The logs can be grouped or classed (e.g. $$F1, F2,...,FN$$) by:
• i) the operating System used (e.g. Android, Windows etc) and
• ii) the error or message generated. The error messages are differentiated by tab white space.

If you cannot work out the log class using some logic, you could look to engineer features with regex to capture the source OS and the tabbed structural information in the error lines.

|---------------------|------------------|
| Error detail        |     n_tabs       |
|---------------------|------------------|
|  string_error       |         0        |
|---------------------|------------------|