kurse:efcomputergrafik:kw48

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
kurse:efcomputergrafik:kw48 [2019/12/04 11:48]
Ivo Blöchliger
kurse:efcomputergrafik:kw48 [2019/12/04 11:48]
Ivo Blöchliger [Text-Analyse mit Python]
Line 113: Line 113:
   * Ctrl-K: Combine (mehrere Pfade in einen Pfad zusammenfassen).    * Ctrl-K: Combine (mehrere Pfade in einen Pfad zusammenfassen). 
  
-===== Text-Analyse mit Python ===== 
-=== Datei einlesen === 
-Von https://stackoverflow.com/questions/7409780/reading-entire-file-in-python 
-<code python> 
-with open('Path/to/file', 'r') as content_file: 
-    content = content_file.read() 
-</code> 
-=== Text finden === 
-https://www.geeksforgeeks.org/string-find-python/ 
-<code python> 
-position = content.find("<path ",startPosition)  # die Startposition ist optional, kann gebraucht werden, um weitere Vorkommen zu finden. 
-if (position!=-1): # Wirklich was gefunden 
-  # tu was damit 
-</code> 
-=== Substring === 
-<code python> 
-a="0123456789" 
-a[2:5] # -> liefert "234" 
-</code> 
-=== Text Analyse === 
-Ist der Path-String einmal gefunden, geht es darum, diesen zu analysieren. Als erster Schritt soll dieser nach Leerschlägen aufgeteilt werden: 
-<code python> 
-txt = "foo bar baz boo" 
-items = txt.split(" ") 
-</code> 
- 
-=== Convertierung in Zahlen === 
-<code python> 
-zahl = float("3.14") 
-</code> 
- 
- 
-<hidden converter.py> 
-<code python converter.py> 
- 
-def convert(elements): 
-    # Aktuelle Koordinaten 
-    x = 0 
-    y = 0 
-    # Position im elements Array 
-    e = 0 
-    # letztes Kommando 
-    lastCMD = "" 
-    while e < len(elements): 
-        if elements[e]=="M":  # Move absolute 
-            x = float(elements[e+1]) 
-            y = float(elements[e+2]) 
-            e = e+3   # 3 Element konsumiert 
-        elif elements[e]=="m":  # Move relative 
-            x = x + float(elements[e+1]) 
-            y = y + float(elements[e+2]) 
-            e = e+3   # 3 Element konsumiert 
- 
- 
- 
-with open('text.svg', 'r') as content_file: 
-    content = content_file.read() 
-     
-# print(content) 
-# Anfangsposition vom path 
-position = content.find("<path") 
-if position<0: 
-    raise BaseException("Kein <path gefunden!") 
- 
-#print("Position %d" % position) 
-# Erste 20 Zeichen vom path 
-#print(content[position:(position+20)]) 
- 
-# d=" suchen... (ab der Position position) 
-while True: 
-    position = content.find("d=\"", position) 
-    if position<0: 
-        BaseException("Kein d= gefunden") 
-         
-    if content[position-1]<'0': # kein Buchstabe vor d 
-        break 
-     
-    position+=1 
-# Erste 20 Zeichen vom d 
- 
-start = position+3 
-ende = content.find("\"", start) 
- 
-pfaddef = content[start:ende] 
-print(pfaddef) 
-pfaddef = pfaddef.replace(",", " ") 
-print(pfaddef) 
-elemente = pfaddef.split(" ") 
-print(elemente) 
- 
-</code> 
-</hidden> 
  
  • kurse/efcomputergrafik/kw48.txt
  • Last modified: 2019/12/04 11:48
  • by Ivo Blöchliger